📜  数据结构|堆叠问题4

📅  最后修改于: 2021-06-29 22:45:43             🧑  作者: Mango

考虑以下使用堆栈的伪代码

declare a stack of characters
while ( there are more characters in the word to read )
{
   read a character
   push the character on the stack
}
while ( the stack is not empty )
{
   pop a character off the stack
   write the character to the screen
}

输入“ geeksquiz”的输出是什么?

(一) geeksquizgeeksquiz
(B) ziuqskeeg
(C)怪胎
(D) ziuqskeegziuqskeeg答案: (B)
说明:由于堆栈数据结构遵循LIFO顺序。当我们从堆栈中弹出()项目时,它们以插入时的相反顺序弹出(或push())。