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打印,堆栈包含
粗体字是pop操作的输出