1#include <stdlib.h>2typedefCharEle;3 4typedefstructnode{5 Ele E;6 structNode *Next;7}lnode,*list;8 9 void Get(Ele);Ten One //construct linked list AList CreateList (intN) { -List L =NULL; -Lnode *p,*r=NULL; the Ele E; - inti; - for(i=0; i<n;i++){ - Get(e); +p = (Lnode *)malloc(sizeof(Lnode)); -P->e=e; + //construct the first element A if(!list) { atL->e=p; -}Else{ -r->next=p; - } -R=p; - } in returnl; - } to + //inserting Nodes - voidInsertlist (List List,lnode *Q,ele e) { theLnode *p = (Lnode *)malloc(sizeof(Lnode)); *P->e=e; $ if(!list) {Panax Notoginsenglist->next=p; -p->next=NULL; the}Else{ + //Assign the latter node to P.next, and the next node of the previous node assigns a value to P AP->next=q->Next; theq->next=p; + } - } $ $ //Delete a node - voidDelnode (List L,lnode *3) { - if(l==q) { theL=q->Next; -}Else{WuyiList temp =list; the while((temp=temp->next)!=q && temp!=NULL) { - } WuTemp->next=q->Next; - Free(q); About } $ } - - //Destroy linked list - voiddestorylist (List list) { ALnode *p,*Q; +p=list; the while(p) { -Q=p->Next; $ Free(p); thep=Q; the } thelist=NULL; the}
LinkedList (C language _ Simple implementation)