Correlation algorithm and application of linked list (III.)

Source: Internet
Author: User

Question six: The same value of two single-linked lists, forming a new linked list

Issue seven: incrementing the output single-linked list and releasing the nodes

Issue eight: A single linked list a leading node is decomposed into two lead nodes of the list A and B to save the original ordinal number of elements, B to save the original sequence number is even the element

Question nine: C={a1,b1,a2,b2,..., an,bn}, split into A={a1,a2,..., an} b={b1,b2,..., bn};

Issue 10: Removing duplicate elements from an ascending ordered list

//question Six the same value of two single-linked lists, forming a new linked listlinklist Common (linklist l1,linklist L2) {Lnode*t1=l1->next,*t2=l2->Next;BOOLYes =0; Lnode*h = (lnode*)malloc(sizeof(Lnode)); H->next=NULL; while(t1) {Yes=0; T2=l2->Next; while(T2) {if(t1->data==t2->data) {Yes=1; Break;} T2=t2->next;}if(yes) {Lnode*node = (lnode*)malloc(sizeof(Lnode)); node->data=t1->Data;node->next=h->next;h->next =node;} T1=t1->next;}returnh;}

//issue seven incrementing the output single-linked list and releasing the nodesvoidMin_del (Linklist &L) {Lnode*pre=l,*p=l->next,*T; while(l->next!=NULL) {Pre=l;p=l->Next; while(p->next!=NULL) {if(p->next->data<pre->next->data) {Pre=p;} P=p->Next;} T=pre->next;printf ("%d",t->data);p re->next=t->Next; Free(t);} Free(L);}

//question eight splitting a single linked list a leading node into a single-linked list A and B with two lead nodes//Save an element with an odd ordinal number in A, and B to save an element with an even number in the originalLinklist discreate (Linklist &A) {linklist B= (linklist)malloc(sizeof(Lnode)); B->next=NULL; Lnode*a=a,*b=C; Lnode*r,*p=a->Next;intindex =1; while(p!=NULL) {if(index%2) {a->next=P;a=p;}Else{b->next=p;b=p;} Index++;p=p->Next;} A->next=null;b->next=NULL;returnB;}

//question Nine will c={a1,b1,a2,b2,..., an,bn}, split into A={a1,a2,..., an} b={b1,b2,..., bn};Linklist DisCreate2 (Linklist &A) {linklist B= (linklist)malloc(sizeof(Lnode)); B->next=NULL; Lnode*r,*a=A;intindex =1; Lnode*p = a->Next; while(p!=NULL) {R=p->Next;if(index%2) {a->next=P;a=p;}Else{p->next=b->Next; B->next=p;} P=R;index++;} A->next=NULL;returnB; }

void Moverepeat (linklist &*pre=l,*p=l->next;    while (p!=null){if(p->next!=null) {if(p->data!=p->next->data) { Pre->next=p;pre=p;}} Else {pre->next=p;pre=p;} P=p->next;} Pre->next=NULL;}

Correlation algorithm and application of linked list (III.)

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.