云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > C语言典型例题(二级考试) - 图文

C语言典型例题(二级考试) - 图文

  • 62 次阅读
  • 3 次下载
  • 2025/5/7 20:30:33

例25 删除指定的节点

struct student *del(struct student *head, long n){structstudent*p1,*p2;/*↑n:要删除学号*/p1=head;

if(p1->num==n)head=p1->next;/*删除首节点*/else

{do{p2=p1;p1=p1->next;

}while(p1!=NULL&&p1->num!=n);if(p1->num==n)p2->next=p1->next;/*找到*/elseprintf(\befound!\\n\/*未找到*/}

free(p1);/*释放被删除节点的存储区*/return(head);/*返回头指针*/}

例26 在链表中插入节点的函数:

structstudent*insert(structstudent*head)

{structstudent*p0,*p1,*p2;longn;intlen;

len=sizeof(structstudent);

p0=(structstudent*)malloc(len);/*申请新节点*/printf(\

scanf(\&p0->num,&p0->score);n=p0->num;/*产生学号副本n*/p1=head;/*从首节点开始查找*/

┇p1=head;/*↓插入在头部*/if(nnum) { p0->next=head; head=p0; }else

{ do /*查找插入位置*/{ p2=p1;

p1=p1->next;

} while(p1!=NULL && n>p1->num);

p0->next=p2->next; /*插入在其余位置*/p2->next=p0;}

return(head);

} /*insert*/

搜索更多关于: C语言典型例题(二级考试) - 图文 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

例25 删除指定的节点struct student *del(struct student *head, long n){structstudent*p1,*p2;/*↑n:要删除学号*/p1=head;if(p1->num==n)head=p1->next;/*删除首节点*/else{do{p2=p1;p1=p1->next;}while(p1!=NULL&&p1->num!=n);if(p1->num==n)p2->next=p1->next;/*找到*/elseprintf(\befound!\\n\/*未找到*/}free(p1);/*释放被删除节点的存储区*/return(head);/*返回头指针*/} 例26 在链表中插入节点的函数:structstudent*in

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com