#include<stdio.h>
#include<malloc.h>
void main()
{
struct node //定义节点
{
char data;
struct node *next;
}*head,*p;
char ch;
head=NULL; //头结点
printf("please input you serial end with enter:\n");//顺序输入
字符串
while((ch=getchar()) && (ch!='\n'))
{
p=malloc(sizeof(struct node));//新建节点p
p->data=ch;
p->next=head;
head=p; //头插法建立链表
}
printf("now show th serial after change:\n");
while(head)
{
p="head";
head="head-">next;
printf("%c",p->data);
// putchar(p->data);//依次打出建立的链表节点
free(p);
}
}
文章评论(0条评论)
登录后参与讨论