求大神帮忙算法分析(请写出下列各算法的功能)算法分析(请写出下列各算法的功能)Void a2(){Queue Q;InitQueue(Q);Char x=’e’,y=’c’;EnQueue(Q,’h’);EnQueue(Q,’r’);EnQueue(Q,’y’);x=DeQueue(Q); EnQueu

来源:学生作业帮助网 编辑:作业帮 时间:2024/04/29 01:06:11

求大神帮忙算法分析(请写出下列各算法的功能)算法分析(请写出下列各算法的功能)Void a2(){Queue Q;InitQueue(Q);Char x=’e’,y=’c’;EnQueue(Q,’h’);EnQueue(Q,’r’);EnQueue(Q,’y’);x=DeQueue(Q); EnQueu
求大神帮忙算法分析(请写出下列各算法的功能)
算法分析(请写出下列各算法的功能)
Void a2()
{Queue Q;
InitQueue(Q);
Char x=’e’,y=’c’;
EnQueue(Q,’h’);
EnQueue(Q,’r’);
EnQueue(Q,’y’);
x=DeQueue(Q); EnQueue(Q,x);
x=DeQueue(Q); EnQueue(Q,’a’);
While(!QueueEmpty(Q))
{ y=DeQueue(Q);
Printf(“%c”,y)
}
Printf(“%c”,x);

求大神帮忙算法分析(请写出下列各算法的功能)算法分析(请写出下列各算法的功能)Void a2(){Queue Q;InitQueue(Q);Char x=’e’,y=’c’;EnQueue(Q,’h’);EnQueue(Q,’r’);EnQueue(Q,’y’);x=DeQueue(Q); EnQueu
把各语句的功能分析如下:
Void a2()
{Queue Q; /* 定义队列 */
InitQueue(Q); /* 初始化队列 */
Char x=’e’,y=’c’; /* 定义两个字符变量并初始化 */
EnQueue(Q,’h’); /* 把h入队 */
EnQueue(Q,’r’); /* 把r入队 */
EnQueue(Q,’y’); /* 把y入队 */
x=DeQueue(Q); EnQueue(Q,x); /* 把队首的h出队到x后,移到队尾 */
x=DeQueue(Q); EnQueue(Q,’a’); /* 把队首的r出队到x,再将a入队 */
While(!QueueEmpty(Q)) /* 当队不空时做 */
{ y=DeQueue(Q); /* 出队元素放到y */
Printf(“%c”,y) /* 打印 y */
}
Printf(“%c”,x); /* 打印 x */
实际打印输出为:
yhar