C ++ doubly-linked notes

#include <stdio.h>
#include <iostream>

// declare doubly linked list node 
struct the Node
{
    you work;
    you y;
    The Node * Next;                                                 // definition of a structure pointer to the next node of the current node; 
    the Node * PREV;                                                 // define a pointer to a structure node; 
};

// declare doubly linked list pointer storage structure 
struct Linklist                                                 @ doubly linked list structure; 
{    
    The Node * head;                                                 // define a head node pointer; 
    the Node * tail;                                                 // define a tail node child node pointer; 
    int size;                                                 // define a variable to hold the number of nodes in the doubly linked list; 
};

// 1. Initialize a doubly-linked list node; 
the Node * the createNode ( int X, int Y)                                 // create a doubly linked list of child nodes; 
{
    Node* temp = (Node*)malloc(sizeof(Node));
    TEMP -> x = x;                                             // the x to x and structure; 
    temp-> = y y;                                             // assign y to y structure;         
    temp-> Next = NULL;                                         // to point to the front and rear node empty address; 
    temp-> PREV = NULL;
     return TEMP;                                             // creates a good structure return; 
}

// 2. Link two nodes; 
void node_link (the Node * N1, the Node * n2)
{
    n1 -> Next = n2;                                             // to point to the next node n1 n2 
    N2-> PREV = n1;                                             // to point to the node n1 n2, a

}

// 3. Initialize 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 a variable to hold the number of nodes in the node; 
}


void push_head(Linklist* list, int x, int y)
{
    IF (list-> head == NULL) // Analyzing doubly-linked list head pointer is empty, then the current node is the first new 
    {
        list->head = 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
    {
        Node* temp = createNode(x, y);
        node_link(temp, list->head);
        list->head = temp;
        list->size++;
    }
}

void  push_end(Linklist* list, int x, int y)
{
    if (list->head == NULL)
    {
        list->head = 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
    {
        Node*  temp= createNode(x, y);
        node_link(list->tail, temp);
        list->tail = temp;
        list->size++;
    }


}


int main ()
{
    LinkList * List = (LinkList *) the malloc ( the sizeof (LinkList));         // dynamically request a doubly-linked list; 
    Linklist_init (List);                                     // initialize doubly linked list; 

    the Node * temp1 the createNode = ( . 1 , . 1 );
    Node *temp2 = createNode(2, 2);
    
    push_end(list,1,2);
    push_end(list, 2, 2);
    push_end(list, 3, 2);
    push_end(list, 4, 2);
    push_head(list, 4, 2);
    push_head(list, 4, 2);
    push_head(list, 4, 2);
    push_head(list, 4, 2);



    return 0;
}

 

Guess you like

Origin www.cnblogs.com/shenji/p/12514911.html