建立并输出一个简单的列表
#include "stdio.h"
struct list{char data;
struct list *next;
};
struct list *create_list()
{struct list *n,*p,*q;
char ch;
h=(struct list *)malloc(sizeof(struct list));
p=q=h;
ch=getchar();
while(ch='*')
{p=(struct list *)malloc(sizeof(struct list));
p->data=ch;
q->next=p;
q=p;
ch=getchar();
p->next=NULL;
return h;
}
void print_list(h)
struct list *h;
{struct list *p;
p=h;
printf("head");
p=p=->next;
while(p!=NULL)
{printf("->%c",p->data);
p=p=->next;}
}printf("\n");
main()
{struct list *head;
head=create_list();
print_list(head);
}