编辑代码

#include <iostream>
#include <bits/stdc++.h>
using namespace std;

typedef int ElemType;
typedef struct Lnode{
    ElemType data;
    struct Lnode *next;
}Lnode,*LinkList;

void InitList(LinkList &L){
    L = (Lnode*)malloc(sizeof(LinkList));
    L->next = NULL;


}

LinkList HeadInsert(LinkList &L){
    InitList(L);
    int x;
    cin>>x;
    while(x!=9999){
        Lnode *s = (Lnode*)malloc(sizeof(Lnode));
        s->data = x;
        s->next = L->next;
        L->next = s;
        cin>>x;
    }
    return L;
}


void PrintList(LinkList &L){
    Lnode *p = L->next;
    while(p){
        cout<<p->data<<" ";
        p=p->next;

    }


}


LinkList TailInsert(LinkList &L){
    InitList(L);
    int x; 
    Lnode *r = L;  
    cin>>x;
    while(x!=9999){
        Lnode *s = (Lnode*)malloc(sizeof(Lnode));
        s->data = x;
        r->next = s;
        r=s;
        cin>>x;
    }
    r->next = NULL;
    return L;
}       

int Length(LinkList &L){
    Lnode *p = L->next;
    int len = 0;
    while(p){
        len++;
        p = p->next;
    }
    return len;
}


Lnode *LocateData(LinkList &L,int x){
    Lnode *p = L->next;
    while(p&&p->data != x){
        p = p->next;
    }
    return p;
}

Lnode *GetData(LinkList &L,int i,int x){
    Lnode *p = GetData(L,i-1);
    Lnode *s = (Lnode*)malloc(sizeof(Lnode));
    s->data = x;
    s->next = p->next;
    p->next = s;


}


int main(){
    LinkList L = TailInsert(L);
    PrintList(L);
}