供参考:
#include <stdio.h>
#include <stdlib.h>
typedef struct node {
int data;
struct node* next;
}Node;
/***********Begin**************/
Node* CreatList()
{
int n;
Node* head = NULL, * p = NULL, * tail = NULL;
head = (Node*)malloc(sizeof(Node));
head->next = NULL;
tail = head;
scanf("%d", &n);
while (n--) {
p = (Node*)malloc(sizeof(Node));
p->next = NULL;
scanf("%d", &p->data);
tail->next = p;
tail = p;
}
return head;
}
void ShowList(Node *phead)
{
Node* p = phead;
if (!p || !p->next)
return;
else {
while (p->next) {
printf(p == phead ? "%d" : " %d", p->next->data);
p = p->next;
}
}
}
/***********End****************/
int main(void)
{
Node* phead;
phead = CreatList();
ShowList(phead);
return 0;
}