📜  数据结构 |堆栈 |问题 4

📅  最后修改于: 2021-09-08 14:52:53             🧑  作者: 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”的输出是什么?

(A)极客测验极客测验
(B) ziuqskeeg
(C)极客测验
(D) ziuqskeegziuqskeeg答案:(乙)
说明:由于堆栈数据结构遵循 LIFO 顺序。当我们从堆栈中 pop() 项时,它们以与插入(或 push())相反的顺序弹出