Data structure and the operation of the algorithm chain list

Source: Internet
Author: User

tepedef struct node{int date;struct Node *next;} list;//creates a list of void creatlist (list **ptrl) {(**ptrl) = (list*) malloc (sizeof (list));(*list)->next=null;} Find length int length (list *ptrl) {list *p=ptrl;int j=0;while (p) {p=p->next;j++;} return J;} Find int findlist (list *ptrl,int k) {list *p=ptrl;int i=1;while (p!=null&&i<k) {p=p->next;i++}if (i=k) by ordinal return P;elsereturn NULL;} Find list *find by value (int x,list *ptrl) {list *p=ptrl;while (p!=null&&p->date!=x) P=p->next;return p;} Insert list* insertlist (int *e,list *ptrl,int i) {list *p,*s;if (i==1)//Insert element in table header {s= (list*) malloc (sizeof (List));s->    Date=x;s->next=ptrl;return s;}    P=find (I-1,ptrl)//If the element to be inserted is empty then return if (p==null) {printf ("Canshucuowu");    return NULL;    } else {s= (list*) malloc (sizeof (List));//insert Operation s->date=x;    s->next=p->next;    p->next=s;    return Ptrl; }}//List deletion list* delsetelist (int *e,list *ptrl,int I,) {List *p,*s; if (i==1) {S=ptrl; if (ptrl!=null) ptrl=ptrl->next; ElseRuturn NULL; Free (s); return Ptrl;     } p=find (I-1,ptrl) if (p==null) {printf ("bucunzia1"); return;  } else {s=p->next; p->next=s->next; free (s); } }

Data structure and the operation of the algorithm chain list

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.