数据结构与算法.pdfVIP

  • 0
  • 0
  • 约2.78千字
  • 约 8页
  • 2026-07-29 发布于江西
  • 举报

编程题

251.试写出在单链表La中删除第i个结点的类C语言算法。

答案:StatusListDeleteL(LinkListL,inti){

p=L;m=0;

while(mi-1p-next)//寻找位置

{p=p-next;m++;}

if(p-next!=null){

q=p-next;

p-next=q-next;

free(q);

}

returnOK;

}//ListDelete_L

_

252.写出求二叉树T中叶子个数的算法。

答案:intcountleaf(BiTree*T){

intn1,n2;

if(T==NULL)return(0);

elseif(T-lchild==NULL)(T-rchild==NULL)

return(1);

else{n1=countleaf(T-lchild);

n2=countleaf(T-rchild);

return(n1+n2);

}

}

253.写出直接插入排序的类C语言算法。

答案:voidInsertSort(SplistL){

for(i=2;i=L-length;i++){

L-r[0]=L-r[i];

for(j=i;L-r[

文档评论(0)

1亿VIP精品文档

相关文档