#include <stdio.h> #include <the iostream> #include <easyx.h> #include <the graphics.h> #include <List> // declare doubly linked list node struct the Node { int X; int Y; the Node * Next; // definition of a structure pointer to the next node of the current node; the node * PREV; // definition of a structure on a pointer to the current node; }; // declare doubly linked list pointer storage structure struct Linklist // bis linked list structure; { the Node* Head; // define a head node pointer; the Node * tail; // node defines the end of a child node pointer; int size; // define a variable to hold the number of nodes in the doubly linked list; }; // 1. Initialize a bis list node; the node * the createNode ( int x, int Y) // create a doubly linked list of child nodes; { the node * TEMP = (the node *) the malloc ( the sizeof (the node)); TEMP -> x = x; // the assignment x x to the structure; temp-> = y y; // assign y to y structure; temp-> the Next = NULL; // front and rear node points to an empty address; temp-> prev = NULL; return the TEMP; // will be created the structure of return; } // 2. link two nodes; void node_link (n1 * the node, the node * N2) { n1 -> next = N2; // to point to the next node n1, N2 N2-> PREV = n1 ; // to point to the node n2, a N1 } // 3. initialized empty doubly-linked list; void Linklist_init (Linklist * List) { List -> head = NULL; // head pointer is NULL; list-> tail = NULL; // tail pointer is also null; list-> size = 0 ; // define variables to hold the the number of nodes in the node; } void push_head (Linklist List *, int X, int Y) { iF (list-> size == 0 ) // determines whether the doubly linked list head pointer is null, then the new current The first node { List -> head = the createNode (X, Y); List-> = tail list-> head; // Since the first node is created, then the first node and a node is empty; list-> size = 1 ; // doubly-linked list stored in the node size becomes 1; } the else { the node * the createNode TEMP = (X, Y); // create a doubly linked list node node_link (TEMP, list-> head); // double linked list because the head mount, the node when the previous parameter passing , list after the list list-> head = TEMP; // head of the head node becomes TEMP list-> size ++; // number of list node bis + 1'd; } } void push_end (Linklist list *, int X, int Y) { IF (list-> == size0 ) { List -> head = the createNode (X, Y); List -> tail = list-> head; // Since the first node is created, then the first node and a node is empty; list-> size = 1 ; // doubly-linked list stored in the node size becomes 1; } the else { the node * TEMP = the createNode (X, Y); node_link (List -> tail, TEMP); // double linked list since the tail mounted , the node at the transmission reference, list the front list-> tail = TEMP; // original node becomes the end of the list TEMP list-> size ++; // number +1 doubly linked list nodes; } } // head starts printing doubly linked list * Print_list_head LinkList (LinkList * List) { IF (list-> head == NULL) return List; the Node * TEMP = list-> head; // application a pointer to the head node of the while (! TEMP = NULL) // determines the current whether the node is empty, otherwise the loop is exited { the printf ( " % D% D-> " , temp-> X, temp-> Y); temp = temp-> next; // the pointer to a node in the temp } the printf ( " NULL \ n- " ); } void Test (* Linklist List) { the while ( . 1) { for (Node* temp = list->head;temp!=NULL; temp = temp->next) { printf("%d,%d->", temp->x, temp->y); } for (Node* temp = list->tail; temp != NULL; temp = temp->prev) { printf("%d,%d->", temp->x, temp->y); } Sleep(1000); } } //从尾部向前打印双链表 Linklist* print_list_end(Linklist* list) { if (list->head == NULL) return List; // if the head node is empty, the doubly linked list is empty the Node * TEMP = list-> tail; // define a node pointer to the tail pointer node the while (! TEMP = NULL) // determines whether the current node is empty { the printf ( " % D% D-> " , temp-> X, temp-> Y); temp = temp-> PREV; // the pointer to a node on the temp }; the printf ( " NULL \ n- " ); } Linklist * free_someone (Linklist List *, int X, int Y) { return List; } int main () { Linklist * List1 = (Linklist *) the malloc ( the sizeof (Linklist)); // dynamically request a doubly-linked list; Linklist_init (List1); for ( int I = . 1 ; I < 10 ; I ++ ) { push_head (List1, I, I); } Test (List1); return 0 ; }