- 论坛徽章:
- 0
|
void main()
{
int n,i;
linklist *L, *S;
creatlist(*&L); //为什么这样调用?creatlist(L);
printf ("Input the items you want:");
scanf ("%d\n",&n);
//在下面的代码中,L为指乡链表头部的指针,S为指向新创建的结构体的指针,你的指向链表表尾的指针在那?
for (i = 0; i < n; i ++ ){
creatlist(*&S);
L -> next = S;
printf ("Input the %d data:", i + 1);
scanf ("%d\n",*&S -> data);
}
outputlist(L);
}
应该这样:
void main()
{
int n,i;
linklist *L, *S,*tmp;
creatlist(L);
tmp=L; //指向链表尾部
printf ("Input the items you want:");
scanf ("%d\n",&n);
for (i = 0; i < n; i ++ ){
creatlist(*&S);
tmp -> next = S; //把S加到表尾
tmp = S; //tmp指向表尾
printf ("Input the %d data:", i + 1);
scanf ("%d\n",&S -> data);
}
outputlist(L);
}
[ 本帖最后由 cceczjxy 于 2006-9-28 13:07 编辑 ] |
|