|
请大家看看,多谢了!
#include <stdio.h>
#include <stdlib.h>
typedef struct node
{
int data;
struct node *next;
}linklist;
void creatlist(linklist *S) /* 就是这个函数的使用,是不是有问题*/
{
S = (linklist *)malloc(sizeof(linklist));
if (S == NULL){
printf ("No enough memory!\n");
}
else {
(S -> next = NULL);
}
}
void outputlist(linklist *S)
{
linklist *P;
P = S -> next;
while (P != NULL){
printf ("%d\t",P -> data);
P = P -> next;
}
printf ("\n");
}
void main()
{
int n,i;
linklist *L, *S;
/* 这里有使用是不是有点问题呢?*/
creatlist(*&L);
printf ("Input the items you want:");
scanf ("%d\n",&n);
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);
} |
|