voi split(lklist *he d,lklist *&h ,lklist *&h ,lklist *&h )
{
lklist *p; h =0,h =0,h =0;
for(p=he d;p!=0;p=he d)
{
he d=p->next; p->next=0;
if (p-> t >=' ' && p-> t <='Z') {p->next=h ; h =p;}
else if (p-> t >='0' && p-> t <='9') {p->next=h ; h =p;} else {p->next=h ; h =p;}
}
}
8. 设计在链式存储结构上交换二叉树中所有结点左右子树的算法。
typedef stru t node {int t ; stru t node *l hild,*r hild;} itree;
voi sw p itree( itree * t)
{
itree *p;
if( t==0) return;
sw p itree( t->l hild); sw p itree( t->r hild);
p= t->l hild; t->l hild= t->r hild; t->r hild=p;
}
9. 在链式存储结构上建立一棵二叉排序树。
#define n 10
typedef stru t node{int key; stru t node *l hild,*r hild;} itree;
voi stinsert( itree *& t,int key)
{
if ( t==0){ t=( itree *)m llo (sizeof( itree)); t->key=key; t->l hild= t->r hild=0;} else if ( t->key>key) stinsert( t->l hild,key); else stinsert( t->r hild,key); }
voi re te sttree( itree *& t)
{
int i;
for(i=1;i<=n;i++) stinsert( t,r ndom(100));
}
10. 设计判断两个二叉树是否相同的算法。
typedef stru t node { t type t ; stru t node *l hild,*r hild;} itree;
int judge itree( itree * t1, itree * t2)
{
if ( t1==0 && t2==0) return(1);
else if ( t1==0 || t2==0 || t1-> t != t2-> t ) return(0);
else return(judge itree( t1->l hild, t2->l hild)*judge itree( t1->r hild, t2->r hild)); }
11. 设计两个有序单链表的合并排序算法。
voi mergelklist(lklist *h ,lklist *h ,lklist *&h )
{
lklist *s=h =0;
while(h !=0 && h !=0)
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-25557-46.html
升级后信号只有一格
年年换中国豆苗大学生