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