|
发表于 2004-8-19 15:43:46
|
显示全部楼层
对不起,刚才正在工作,修改如下:
#include <stdio.h>
#include <malloc.h>
typedef struct node
{
int data;
struct node *next;
}LINKLIST;
int main()
{
int e;
LINKLIST *head=NULL,*p,*q;
printf("输入非0数据(0为结束)\n");
scanf("%d",&e);
while(e!=0)
{
p=(struct node *)malloc(sizeof(struct node));
if (head == NULL) {
head=p;
head->data=e;
head->next=NULL;
q=head;
} else {
q->next=p;
p->data=e;
p->next=NULL;
q=p;
}
scanf("%d",&e);
}
//打印链表
while(head != NULL)
{
printf("head->data is %d\n",head->data);
head=head->next;
}
printf("over\n");
return 0;
} |
|