哪位高手帮忙看看这个数据结构的题哪里不对

来源:百度知道 编辑:UC知道 时间:2024/05/01 21:45:56
#include "stdio.h"
#include "stdlib.h"

typedef struct node
{
int data;
struct node *next;
}LNode,*LinkList;

LinkList create1()
{
LinkList L=NULL;
LNode *s;
int x;
scanf("%d",&x);
while(x!=NULL)
{
s=malloc(sizeof(LNode));
s->data=x;
s->next=L;
L=s;
scanf("%d",&x);
}
return L;
}

LinkList create2()
{
LinkList L=NULL;
LNode *s,*r=NULL;
int x;
scanf("%d",&x);
while(x!=NULL)
{
s=malloc(sizeof(LNode));
s->data=x;
if(L==NULL)L=s;
else r->next=s;
r=s;
scanf("%d",&x);
}
if(r!=NULL)r->next=NULL;
return L;
}

outputlist(LinkList L)
{<

outputlist(LinkList L)
{
LNode *p=L;
while(p!=NULL)
{
printf("%d ",*p);
p++; //肯定是这里问题!!!!malloc每次申请的内存不是连续的!!!!!!!
} //把p++改成p=p->next;应该没有问题的,如果是结构体组或者堆栈就可以
//这么用
printf("\n");
getch();
}

循环时
你试以下啊:
for x:= 2 to ? do