单链表创建和显示元素

#include
#include
#include
using namespace std;

typedef struct LNode{
int data;
struct LNode *next;
}LNode,*LinkList;
void CreateList_L(LinkList &L,int n){
int i;
LNode *p;

L->next=NULL;
cout<<"Please input the data in the LinkList:"< for(i=n;i>0;--i){
p=(LinkList)malloc(sizeof(LNode));
cin>>p->data;
p->next=L->next;
L->next=p;
}
if(n)
cout<<"Success to create a LinkList!"< else
cout<<"A NULL LinkList has been create!"< }
void display(LinkList &L){
//LNode *p;
//L=(LinkList)malloc(sizeof(LNode));
cout<<"The data is:"< while(L!=NULL){
//p=(LinkList)malloc(sizeof(LNode));
cout<data< L=L->next;

}
}
void main(){
LinkList L,head;
L=(LinkList)malloc(sizeof(LNode));
head=L;
head->data=0;
int LinkListNum;
cout<<"Please input the LinkListNum:"< cin>>LinkListNum;
CreateList_L(L,LinkListNum);
cout<<"OK...!"< display(head);
getch();
}

你可能感兴趣的:(单链表创建和显示元素)