Data structures 为输入提供java堆栈打印的输出
我对这个作业和堆栈的数据结构有点困惑。基本上,问题是:Data structures 为输入提供java堆栈打印的输出,data-structures,stack,Data Structures,Stack,我对这个作业和堆栈的数据结构有点困惑。基本上,问题是: "Give the output printed by java Stack for the input" 下面是输入 it was - the best - of times - - - it was - the - - 输出将在应答键中 was best times of the was the it (1 left on stack) 我不明白您将如何接收这个输出,我尝试编写自己的堆栈结构,但如果我迭代它,我只会先入先出 任何帮
"Give the output printed by java Stack for the input"
下面是输入
it was - the best - of times - - - it was - the - -
输出将在应答键中
was best times of the was the it (1 left on stack)
我不明白您将如何接收这个输出,我尝试编写自己的堆栈结构,但如果我迭代它,我只会先入先出
任何帮助都可以,我将不胜感激。没有明确说明,但从输入来看,我假设单词被推到堆栈上,而
-
符号是弹出操作。如果是这种情况,那么操作是
- 按下
,堆栈包含it
李>it
- 推送
,堆栈包含was
它
李>was
- pop prints是,堆栈包含它李>
- 按下
,堆栈包含the
it
李>the
- 按
,堆栈包含最佳
它
李>最佳
- pop打印最佳,堆栈包含
它
李>的
- 按
的
,堆栈包含
它
的
李>
- 按
,堆栈包含次
它
次
的
李>
- pop打印次,堆栈包含
它
的
李>
- 弹出打印的,堆栈包含
它
李>的
- pop打印该,堆栈包含
李>它
- 按下
,堆栈包含it
it
李>it
- 推送
,堆栈包含was
它
它
李>was
- pop打印是,堆栈包含
它
李>它
- 按下
,堆栈包含the
it
it
李>the
- pop打印该,堆栈包含
它
李>它
- pop打印它,堆栈包含
它
- 按