单向链结串列删除节点.PPT

  1. 1、本文档共111页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
单向链结串列删除节点

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 雙向鏈結串列刪除節點(4) /* [名稱]:ch03_12.cpp [示範]:雙向鏈結串列中節點的刪除 */ #include iostream #include cstdlib #include ctime #include iomanip using namespace std; class list { public: int num,score; char name[10]; class list *llink; class list *rlink; }; typedef class list node; typedef node *link; link findnode(link head,int num) { link ptr; ptr=head; while(ptr!=NULL) { if(ptr-num==num) return ptr; ptr=ptr-rlink; } return ptr; } link deletenode(link head,link del) { if(head==NULL) //雙向串列是空的 { cout[串列是空的]endl; return NULL; } if(del==NULL) { cout[錯誤:不是串列中的節點]endl; return NULL; } if(del==head) { head=head-rlink; head-llink=NULL; } else { if(del-rlink==NULL) //刪除串列尾 { del-llink-rlink=NULL; } else //刪除中間節點 { del-llink-rlink=del-rlink; del-rlink-llink=del-llink; } } free(del); return head; } int main() { link head,ptr; link llinknode=NULL; link newnode=NULL; int new_num, new_score; char new_name[10]; int i,j,position=0,find,data[12][2]; char namedata[12][10]={{Allen},{Scott},{Marry} ,{John},{Mark},{Ricky},{Lisa} ,{Jasica},{Hanson},{Amy},{Bob},{Jack}}; srand((unsigned)time(NULL)); cout座號 成績 座號 成績 座號 成績 座號 成績endl; cout==============================================endl; for(i=0;i12;i++) { data[i][0]=i+1; data[i][1]=rand()%50+51; } for(i=0;i3;i++) { for (j=0;j4;j++) cout[setw(2)data[j*3+i][0] ] [setw(3)data[j*3+i][1]] ; coutendl; } head=new node; //建立串列首 if(head==NULL) { coutError!! 記憶體配置失敗!!endl; exit(1); } else { head=new node; head-num=data[0][0]; for (j=0;j10;j++) head-name[j]=namedata[

文档评论(0)

xiaozu + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档