作者在 2010-03-22 22:23:03 发布以下内容
#include "iostream.h"
#include "malloc.h"
typedef struct LNode
{
int data;
struct LNode *next;
}LNode,*LinkList;
void CreateList(LinkList L)
{
LinkList p,q;
int i=1;
L=(LNode*)malloc(sizeof(LNode));
if(L==NULL)
cout<<"error!";
p=L;
while(p!=NULL&&i!=0)
{
q=(LNode*)malloc(sizeof(LNode));
if(q==NULL)
cout<<"malloc error"<<endl;
cout<<"input the data(end with 0):"<<endl;
cin>>q->data;
i=q->data;
p->next=q;
p=q;
#include "malloc.h"
typedef struct LNode
{
int data;
struct LNode *next;
}LNode,*LinkList;
void CreateList(LinkList L)
{
LinkList p,q;
int i=1;
L=(LNode*)malloc(sizeof(LNode));
if(L==NULL)
cout<<"error!";
p=L;
while(p!=NULL&&i!=0)
{
q=(LNode*)malloc(sizeof(LNode));
if(q==NULL)
cout<<"malloc error"<<endl;
cout<<"input the data(end with 0):"<<endl;
cin>>q->data;
i=q->data;
p->next=q;
p=q;
}
}
void PrintList(LinkList L)
{
LinkList p;
p=L->next;
while(p!=NULL)
{
cout<<p->data<<endl;
p=p->next;
}
}
void main()
{
LNode L;
CreateList(&L);
PrintList(&L);
}
}
void PrintList(LinkList L)
{
LinkList p;
p=L->next;
while(p!=NULL)
{
cout<<p->data<<endl;
p=p->next;
}
}
void main()
{
LNode L;
CreateList(&L);
PrintList(&L);
}