我写了个逆序的没有问题,,感觉正序的应当简单才行,居然出了问题
真郁闷!!!!
#include"stdio.h"
#include"stdlib.h"
#include"malloc.h"
#define null 0
typedef struct Lnode
{
int date;
struct Lnode *next;
}Node,*LinkList;
void CreatList(LinkList &L,int n);
void print(LinkList &L);
void CreatList(LinkList &L,int n)
{
LinkList s, p=L;
int i;
for(i=0;i<n;i++)
{
s=(LinkList)malloc(sizeof(Node));
if(!s) exit(1);
scanf("%d",&s->date);
s->next=null;
p->next=s;
p=s;
}
}
void print(LinkList &L)
{
LinkList p=L->next;
printf("********************************\n");
while(p)
{
printf("%d ",p->date);
p=p->next;
}
printf("\n********************************\n");
}
int main()
{
int n;
LinkList L;
printf("Please Input how many NOdes do you want:");
scanf("%d",&n);
printf("Please Input the NOdes you want:");
CreatList(L, n);
print(L);
return 0;
}
[此贴子已经被作者于2006-5-17 19:04:34编辑过]