if(h -> t <h -> t ){if(s==0) h =s=h ; else {s->next=h ; s=h ;};h =h ->next;}else {if(s==0) h =s=h ; else {s->next=h ; s=h ;};h =h ->next;}
if(h ==0) s->next=h ; else s->next=h ;
}
12. 设计在顺序有序表中实现二分查找的算法。
stru t re or {int key; int others;};
int ise r h(stru t re or r[ ], int k)
{
int low=0,mid,high=n-1;
while(low<=high)
{
mid=(low+high)/2;
if(r[mid].key==k) return(mid+1); else if(r[mid].key>k) high=mid-1; else low=mid+1; }
return(0);
}
13. 设计判断二叉树是否为二叉排序树的算法。
int minnum=-32768,fl g=1;
typedef stru t node{int key; stru t node *l hild,*r hild;} itree;
voi inorder( itree * t)
{
if ( t!=0) {inorder( t->l hild); if(minnum> t->key)fl g=0; minnum= t->key;inorder( t->r hild);} }
14. 在链式存储结构上设计直接插入排序算法
voi str ightinsertsort(lklist *&he d)
{
lklist *s,*p,*q; int t;
if (he d==0 || he d->next==0) return;
else for(q=he d,p=he d->next;p!=0;p=q->next)
{
for(s=he d;s!=q->next;s=s->next) if (s-> t >p-> t ) re k;
if(s==q->next)q=p;
else{q->next=p->next; p->next=s->next; s->next=p; t=p-> t ;p-> t =s-> t ;s-> t =t;}
}
}
15. 设计在链式结构上实现简单选择排序算法。
voi sele tsorlklist(lklist *&he d)
{
lklist *p,*q,*s; int min,t;
if(he d==0 ||he d->next==0) return;
for(q=he d; q!=0;q=q->next)
{
min=q-> t ; s=q;
for(p=q->next; p!=0;p=p->next) if(min>p-> t ){min=p-> t ; s=p;}
if(s!=q){t=s-> t ; s-> t =q-> t ; q-> t =t;}
}
}
16. 设计在顺序存储结构上实现求子串算法。
voi su string( h r s[ ], long st rt, long ount, h r t[ ])
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-25557-47.html
我见过好
他也是命好
不行