程序代码:
head=(headlink *)malloc(sizeof(headlink)); head->next=NULL; while(p)//这里判断有点问题,简单的写法就是上面定义个变量int i=0;这里写上i++<n;n表示链表长 { p=(headlink *)malloc(sizeof(headlink)); p->info=c; p->next=head->next; head->next=p; }
剑栈风樯各苦辛,别时冰雪到时春
#include<stdio.h> #include<stdlib.h> typedef struct Node { char info; struct Node *next; }headlink; headlink *creat() { headlink *head, *p; char c; head=NULL; while((c=getchar())!='\n') { p=(headlink *)malloc(sizeof(headlink)); p->info=c; p->next=head; head=p; } return (head); } void print(headlink *head) { headlink *p; p=head; while(p) { putchar(p->info); p=p->next; } } int main() { headlink *head; head = creat(); print(head); system("pause"); return 0; }