A doubly linked list is also called a doubly linked list, which is a list of two pointers in each data node, pointing directly to successive and direct precursors respectively. So, starting from any node in a doubly linked list, it is easy to access its predecessor and successor nodes. In general, we construct two-way circular linked lists .
typedef struct node{
struct node *pre; //precursor pointer
int age ;
struct node *next; //Rear drive hands
}node;
int Main (int argc, const Char * argv[]) {
Node * phead = NULL;
Node * ptail = NULL;
for (int i = 0; i<5; i++) {
node * ptemp = (node*)malloc (1*sizeof (node));
if (ptemp = = NULL) {
exit(exit_failure);
}
printf(" Please enter Age:");
scanf("%d",&ptemp->age);
if (phead==NULL) {
ptemp->Pre = NULL;
Phead = ptemp;
ptail = ptemp;
}Else{
ptail->Next = ptemp; Connect to temp with the tail pointer first
Ptemp->Pre = ptail; Then connect the upper tail pointer with temp
Ptail = ptemp; The tail pointer points to the TEMP pointer
Phead->Pre = ptail; The head pointer points to the tail pointer to form a loop
Ptail->Next = Phead; The tail pointer points to the head pointer to form a loop
}
}
Node * ptemp = phead;
while (ptemp! = NULL) {
printf("%d",ptemp->age);
Ptemp = ptemp->next;
if (ptemp==phead) {
break;
}
}
return 0;
}
1216.1--Double Linked list