注意:此页面搜索的是所有试题
设栈S=(1,2,3,4,5,6,7),其中7为栈顶元素。请写出调用algo(&s)后栈S的状态。

void algo(Stack *S)
{
int i=0;
Queue Q; Stack T;
InitQueue(&Q);InitStack(&T);
while (!StackEmpty(S))
{
if((i=!i)!=0)Push(&T,Pop(&S));
else EnQueue(&Q,Pop(&S));
}
while(!QueueEmpty(Q))
Push(&S,DeQueue(&Q));
while(!StackEmpty(T))
Push(&S,Pop(&T));
}

参考答案