1216.1--Double Linked list

Source: Internet
Author: User

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

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.