首页 > 代码库 > Doubly_Linked_List

Doubly_Linked_List

 1 #include <iostream> 2 #include <string> 3 #include <cstdio> 4 #include <cstdlib> 5  6 using namespace std; 7  8 struct Dulist 9 {10     int data;11     Dulist *prior;12     Dulist *next;13 };14 Dulist *head;15 void Init_Node()16 {17     head->data = http://www.mamicode.com/0;18     head->prior = NULL;19     head->next = NULL;20 }21 22 void Insert_Node(Dulist *Q, int data, int index)23 {24     Dulist *p = (Dulist *)malloc(sizeof(Dulist));25     p = head;26     for (int i = 0; i < index; i++)27     {28         p = p->next;29     }30     Q->prior = p;31     p->next->prior = Q;32     Q->next = p->next;33     p->next = Q;34 }35 36 void Delete_Node(int index)37 {38     Dulist *p = (Dulist *)malloc(sizeof(Dulist));39     p = head;40     for (int i = 0; i < index; i++)41     {42         p = p->next;43     }44     p->prior->next = p->next;45     p->next->prior = p->prior;46 }47 48 int main()49 {50 51 }

 

Doubly_Linked_List