- #include"stdio.h"
- #include"malloc.h"
- typedef struct Node
- { char data;
- struct Node *next;
- }Node,*Linklist;
- void Input(Linklist &p)//输入函数
- { Node *r,*s;
- r=p;
- char c;
- int flag=1;
- while(flag)//标记
- { c=getchar();//读入字符
- if(c!='#')
- {
- s=(Node *)malloc(sizeof(Node));//动态分配空间
- s->data=c;//将读入的字符存储在s中
- r->next=s;
- r=s;
- }
- else
- { flag=0;//当输入的字符为#时结束循环
- r->next=NULL;//将尾指针设置为空
- }
- }
- }
- void Output(Linklist &p)//输出函数
- {
- Linklist L;
- L=p->next;
- while(L)//当L不为空
- {
- printf("%c",L->data);
- L=L->next;
- }
- }
- void main()
- { Linklist p;//定义变量
- p=(Node *)malloc(sizeof(Node));//初始化
- Input(p);//输入
- Output(p);//输出
- }
本文出自 “阿凡达” 博客,请务必保留此出处http://shamrock.blog.51cto.com/2079212/817857