b2科目四模拟试题多少题驾考考爆了怎么补救
b2科目四模拟试题多少题 驾考考爆了怎么补救

二叉排序树的建立_怎么建立二叉排序树_二叉排序树的创建(46)

电脑杂谈  发布时间:2017-01-11 12:04:54  来源:网络整理

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

相关阅读
    发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

    每日福利
    热点图片
    拼命载入中...