写出下列程序段的输出结果(队列中的元素类型QElemType为char)
voidmain(){
QueueQ;
InitQueue(Q);
Char x='e';
y='c';
EnQueue(Q,'h');
EnQueue(Q,'r');
EnQueue(Q,y);
DeQueue(Q,x);
EnQueue(Q,x);
DeQueue(Q,x);
EnQueue(Q,'a');
while(!QueueEmpty(Q)){
DeQueue(Q,y);
printf(y);
};
Printf(x);
}
答案为:char
代码分析:
队列为先进先出原则
voidmain(){
QueueQ; //定义一个队列
InitQueue(Q); //初始化一个队列
Char x='e';
y='c';
EnQueue(Q,'h'); //进队一个‘h’,此时队列中有:h
EnQueue(Q,'r'); //进队一个‘r’,此时队列中有:hr
EnQueue(Q,y); //进队一个‘c’,此时队列中有:hrc
DeQueue(Q,x); //将对头元素赋值为x,出队一个‘h’,此时队列中有:rc
EnQueue(Q,x); //进队一个‘h’,此时队列中有:rch
DeQueue(Q,x); //将对头元素令为x,出队一个‘r’,此时队列中有:ch
EnQueue(Q,'a'); //进队一个‘a’,此时队列中有:cha
while(!QueueEmpty(Q)){ //循环输出队列里的元素直至空
DeQueue(Q,y); //将对头元素赋值为为y,出队一个y
printf(y); //输出y
};
Printf(x); //输出x
}