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

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

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

while (i<j && r[i]<x) i=i+1; if (i<j) {r[j]=r[i];j=j-1;}

}

r[i]=x;

}

4. 设有两个集合 和集合 ,要求设计生成集合 = ∩ 的算法,其中集合 、 和 用链式存

储结构表示。

typedef stru t node {int t ; stru t node *next;}lklist;

voi interse tion(lklist *h ,lklist *h ,lklist *&h )

{

lklist *p,*q,*t;

for(p=h ,h =0;p!=0;p=p->next)

{ for(q=h ;q!=0;q=q->next) if (q-> t ==p-> t ) re k;

if(q!=0){ t=(lklist *)m llo (sizeof(lklist)); t-> t =p-> t ;t->next=h ; h =t;}

}

}

5. 设计在单链表中删除值相同的多余结点的算法。

typedef int t type;

typedef stru t node { t type t ; stru t node *next;}lklist;

voi delredun nt(lklist *&he d)

{

lklist *p,*q,*s;

for(p=he d;p!=0;p=p->next)

{

for(q=p->next,s=q;q!=0; )

if (q-> t ==p-> t ) {s->next=q->next; free(q);q=s->next;}

else {s=q,q=q->next;}

}

}

6. 设计一个求结点x在二叉树中的双亲结点算法。

typedef stru t node { t type t ; stru t node *l hild,*r hild;} itree;

itree *q[20]; int r=0,f=0,fl g=0;

voi preorder( itree * t, h r x)

{

if ( t!=0 && fl g==0)

if ( t-> t ==x) { fl g=1; return;}

else {r=(r+1)% 20; q[r]= t; preorder( t->l hild,x); preorder( t->r hild,x); }

}

voi p rent( itree * t, h r x)

{

int i;

preorder( t,x);

for(i=f+1; i<=r; i++) if (q[i]->l hild-> t ==x || q[i]->r hild-> t ) re k;

if (fl g==0) printf("not foun x\n");

else if (i<=r) printf("% ", t-> t ); else printf("not p rent");

}

7. 设单链表中有仅三类字符的数据元素(大写字母、数字和其它字符),要求利用原单链

表中结点空间设计出三个单链表的算法,使每个单链表只包含同类字符。

typedef h r t type;

typedef stru t node { t type t ; stru t node *next;}lklist;


本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-25557-45.html

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

    热点图片
    拼命载入中...