First Node single linked list

Code:

/ * 
 * Lead single linked list node 
 * / 
#include <the iostream> 
#include <stdlib.h>
 the using  namespace STD; 

typedef struct ListNode 
{ 
    int Data;
     struct ListNode * Next; 
} the Node, * PNode; 

// new node, num is the number of nodes 
PNode NewNode ( int num) 
{ 
   // new head node 
    PNode head = (PNode) the malloc ( the sizeof (the node));
     IF (head == NULL) 
    { 
        COUT << " head node memory allocation failure !" ; 
        Exit ( 0 ); 
    } 

    PNode TEMP = head; 
    TEMP -> Next = NULL; 

    for ( int I = 0 ; I <NUM; I ++ ) 
    { 
        // data of the current node 
        int NUM; 
        CIN >> NUM;
         / / new node 
        PNode = node (PNode) the malloc ( the sizeof (the node));
         IF (node == NULL) 
        { 
            COUT << " node memory allocation failure! "  ;
            Exit ( 0 ); 
        } 
        Node -> Data = NUM; 

        temp -> Next = Node; 
        temp = Node; // make a new junction point temp 
    }
     return head; // return the first node 
}
 // delete node, temp means to delete the list of several nodes 
void as Free (PNode node, int TEMP) 
{ 
    int NUM = . 1 ;
     the while (TEMP =! NUM) 
    { 
        node = node-> Next; 
        NUM ++ ; 
    } 
    node -> Next = node-> next-> Next; 
} 
// at the end of the insertion node, temp inserted data represents 
void Insertoftail (PNode Node, int TEMP) 
{ 
    the while (node-> Next = NULL!) // Note Analyzing with the proviso that node-> next = NULL;! node points to the last stop 
    { 
        node = node-> Next; 
    } 
    PNode New = (PNode) the malloc ( the sizeof (the node));
     IF (New == NULL) 
    { 
        COUT < < " node memory allocation failure! " ; 
        Exit ( 0 ); 
    } 
    New -> Data =TEMP; 
    Node -> Next = New; 
} 
// The linked list data and to find the location, find the first one found only 
void Search (PNode Node, int TEMP) 
{ 
    Node = node-> Next;
     int NUM = 0 ;
     the while (the Node =! NULL) 
    { 
        NUM ++ ;
         IF (node-> the Data == the TEMP) 
        { 
            cout << " number you are looking for ." << << the TEMP " in " << << NUM " bit " << endl;
            return;
        } 
        Node = node-> Next; 
    } 
    COUT << " Not Found! " << endl; 
} 
// output linked list data 
void the Printf (PNode Node) 
{ 
    Node = node-> Next; // head node to skip 
    the while ( = Node! NULL) 
    { 
        COUT << node-> Data << "  " ; 
        Node = node-> Next; 
    } 
    COUT << endl;
}
int main()
{
    ListNode* head=NewNode(7); // Create the list of length 7, data is clocked into 
    the Printf (head); // output current linked list data 
    Search (head, 8 ); // Find data node 8 
    Insertoftail (head, 99 ); // 99 is inserted at the end of the data node 
    the Printf (head); // output current linked list data 
    as Free (head, . 1 ); // delete the first node 
    the Printf (head); // output current linked list data 
    return  0 ; 
}

 Screenshot experiment:

Guess you like

Origin www.cnblogs.com/handsometaoa/p/12067042.html