#include
#include
struct node
{int data;
struct node *next;
};
struct node *create()
{
struct node *p;
p=(struct node *)malloc(sizeof(struct node));
p->next=0;
return p;
}
void show(node *head)
{
head=head->next;
while(head!=NULL)
{
printf("%d\n",head->data);
head=head->next;
}
}
void main()
{
struct node *head,*q,*p,*t;
int i;
int x;
head=create();
for(i=1;i<=10;i++)
{
printf("please input data:");
scanf("%d",&x);
q=create();
q->data=x;
if(i==1)
{
head->next=q;
p=q;
}
else
{p->next=q;
p=q;}
}
show(head);
}
#include
#include
struct node {
int data;
struct node *next;
};
struct node *create()
{
struct node *p;
p=(struct node *)malloc(sizeof(struct node));
p->next=0;
return p;
}
void list_print(struct node *head)
{
struct node *pos;
for (pos = head->next; pos != NULL; pos = pos->next) {
printf("%d\n", pos->data);
}
return;
}
int main()
{
struct node *head,*q,*p;
int i;
int x;
head=create();
for(i = 1; i <= 10; i++) {
printf("please input data[%d]:", i);
scanf("%d",&x);
q=create();
q->data=x;
if(i==1) {
head->next=q;
p=q;
} else {
p->next=q;
p=q;
}
}
list_print(head); //这个样子就行了
return 0;
}
直接用printf把节点的data输出就好了哇