编写一个读入一个字符串,把它顺序读入队列,并输出队列的程序。

来源:百度知道 编辑:UC知道 时间:2024/07/02 09:42:00

字符入队列
struct node
{
char c;
struct node *next;
};
struct node *Q;//Q为队头,无数据
//用栈实现队列;
//输入ESC则退出,输入回车则换行
struct node *Input(void)
{
struct node *p,*t;//临时结点指针
char char;
p=struct node * malloc(sizeof(struct node));
Q=p;Q->next=NULL;
t=p;
scanf("%c",&char);
while(char!=27)//输入字符,直到ESC结束
{
p=struct node * malloc(sizeof(struct node));
p->c=char;
t->next=p;//把输入的字符插入队列中
t=p;
p->next=NULL;
scanf("%c",&char);
}
}
void Print(struct node *Q)
{
struct node *p;
p=Q->next;
while(p->c!=27&&p)
{
if(p->c==13)printf("\n");//输出换行符
else printf("%c",p->c);
}
}