Cyclic link list Merging

Source: Internet
Author: User

Book title, lead list & not lead linked list

Do not lead the list is empty, Judge: head==null;

The lead list is empty Yes, Judge head->next=null;

But for the list of inserts, delete will be different, do not lead the list for the head node needs to be processed separately, and for the lead linked list does not need

1#include <iostream>2 using namespacestd;3typedefstructnode4 {5     intdate;6     structnode*Next;7}*Linklist,listnode;8 linklist initlist (linklist head)9 {TenHead=NewListNode; Onehead->next=NULL; A     returnhead; - } - voidInput (linklist head,intN) the { -Linklist tail=null,temp=NULL; -      while(n--) -     { +         if(tail==NULL) -         { +Cin>>head->date; ATail=head; at         } -         Else -         { -temp=NewListNode; -Cin>>temp->date; -tail->next=temp; inTail=temp; -tail->next=NULL; to         } +     } -tail->next=head; the } * linklist Bin (linklist head1,linklist head2) $ {Panax NotoginsengLinklist p=Head1,tail; -      while(p->next!=head1) theP=p->Next; +Tail=p; Atail->next=head2; thep=head2; +      while(p->next!=head2) -P=p->Next; $p->next=Head1; $     returnp; - } - voidoutputlist (linklist head) the { -Linklist p=head;Wuyi      while(p!=NULL) the     { -cout<<p->date<<' '; WuP=p->Next; -     } About } $ intMain () - { -Linklist head1,head2,tail=null,p; -head1=initlist (head1); AHead2=initlist (head2); +Input (Head1,5); theInput (head2,5); -Tail=bin (head1,head2); $p=Head1; the      while(p!=tail) the     { thecout<<p->date<<' '; theP=p->Next; -     } inCout<<tail->date; the     return 0; the}

Cyclic link list Merging

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.