日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

循环链表合并

發(fā)布時間:2024/4/17 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 循环链表合并 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

書上的題目,帶頭鏈表&不帶頭鏈表

不帶頭鏈表為空時,判斷:head==NULL;

帶頭鏈表為空是,判斷head->next=NULL;

但對于鏈表的插入、刪除會有不同,不帶頭鏈表對于頭節(jié)點需要單獨處理,而對于帶頭鏈表則不需要

1 #include <iostream> 2 using namespace std; 3 typedef struct node 4 { 5 int date; 6 struct node* next; 7 }*linklist,listnode; 8 linklist initlist(linklist head) 9 { 10 head=new listnode; 11 head->next=NULL; 12 return head; 13 } 14 void input(linklist head,int n) 15 { 16 linklist tail=NULL,temp=NULL; 17 while(n--) 18 { 19 if(tail==NULL) 20 { 21 cin>>head->date; 22 tail=head; 23 } 24 else 25 { 26 temp=new listnode; 27 cin>>temp->date; 28 tail->next=temp; 29 tail=temp; 30 tail->next=NULL; 31 } 32 } 33 tail->next=head; 34 } 35 linklist bin(linklist head1,linklist head2) 36 { 37 linklist p=head1,tail; 38 while(p->next!=head1) 39 p=p->next; 40 tail=p; 41 tail->next=head2; 42 p=head2; 43 while(p->next!=head2) 44 p=p->next; 45 p->next=head1; 46 return p; 47 } 48 void outputlist(linklist head) 49 { 50 linklist p=head; 51 while(p!=NULL) 52 { 53 cout<<p->date<<' '; 54 p=p->next; 55 } 56 } 57 int main() 58 { 59 linklist head1,head2,tail=NULL,p; 60 head1=initlist(head1); 61 head2=initlist(head2); 62 input(head1,5); 63 input(head2,5); 64 tail=bin(head1,head2); 65 p=head1; 66 while(p!=tail) 67 { 68 cout<<p->date<<' '; 69 p=p->next; 70 } 71 cout<<tail->date; 72 return 0; 73 }

?

轉(zhuǎn)載于:https://www.cnblogs.com/a1225234/p/4662481.html

總結(jié)

以上是生活随笔為你收集整理的循环链表合并的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。