Linear Table - single linked list First Node

#include <the iostream> 
#include <Vector> 

the using namespace STD; 

// structure defines 
#define the maxSize 50 
typedef struct {LNode 
    int Data; 
    LNode * Next; 
} LNode, * LinkList; 

establishing a single linked list // head interpolation 
LinkList List_HeadInsert ( L & LinkList) { 
    LNode S *; 
    int elem; 
    // build the first node 
    L = new new LNode; 
    L-> Next = nullptr a; 

    CIN >> elem; 

    ! the while (elem = -1) { 
        S = new new LNode; 
        S- > Data = elem; 
        S-> Next = L-> Next; 
        L-> Next = S; 
        CIN >> elem; 
    } 
    return L; 
} 

// end of the list to establish a single interpolation
LinkList List_TailInsert(LinkList &L){
    LNode new new = L; 
    L-> Next = nullptr a; 
    LNode S *, L * = R & lt; 
    int elem; 

    CIN >> elem; 
    the while (elem = -1!) { 
        S = new new LNode; 
        S-> Data = elem; 
        R-> Next = S; 
        R & lt = S; 
        CIN >> elem; 
    } 
    R-> Next = nullptr a; 
    return L; 
} 

// find a node in sequential 
LNode getElem * (L & LinkList, I int) { 
    IF (I 0 ==) { 
        return L; 
    } 
    IF (I <0) { 
        return nullptr a; 
    } 
    LNode* p = L;
    while(p != nullptr && i--){
        p = p->next;
    } 
    COUT p-<<> Data; 
    return P; 
} 

// lookup table value node by
LNode *LocateElem(LinkList &L,int e){
    if(L->next == nullptr){
        return nullptr;
    }
    LNode * p = L->next;
    while(p != nullptr && p->data != e){
        p =p->next;
    }
    return p;
}

   

Guess you like

Origin www.cnblogs.com/buaaZhhx/p/12367333.html