Two-way loop linked list is formed two rings, note that each ring end-to-end connection is basic.
The program uses the tail interpolation method to add nodes.
1#include <stdio.h>2#include <stdlib.h>3 #defineelement int4typedefstructnode{5element data; 6 structNode *Next; 7 structNode *Prior; 8}*Pnode; 9 Ten //build a new double loop list Oneelement Init_list (Pnode p) A { - //Pnode r=null; - //*p= (pnode) malloc (sizeof (Pnode)); thep->next=p; -P->prior=p; - return 0; - } + //creat a new double loop list -Element Build_list (Pnode *l,element num) + { APnode p=NULL; atPnode r=NULL; - intI=0; - intj=0; -p=*L; - for(j=0; j<num;j++) - { inR= (Pnode) malloc (sizeof(Pnode)); -R->data=J; top->next=R; +R->prior=p; -r->next=p; theP->prior=R; *printf"flag:%d\n",p->next->data); $p=R;Panax Notoginseng //printf ("flag:%d\n", p->next->data); - } the return 0; + } Aelement Print_list (pnode L) the { + if(!L) - { $printf"It is empty\n"); $ } -Pnode p=L; -P=p->Next; the intI=0; - while(i< -) Wuyi { theprintf"data:%d\n",p->data); -P=p->Next; Wui++; - } About $ return 0; - } - intMain () - { APnode p=NULL; +Pnode m=NULL; thep= (Pnode) malloc (sizeof(Pnode)); -init_list (P); $M=build_list (&p,Ten); theprint_list (P); the return 0; the}
C Programming Two-way circular chain list