【问题标题】:Give the output printed by java Stack for the input给出 java Stack 打印的输出作为输入
【发布时间】:2020-03-11 00:19:09
【问题描述】:

我对这个作业和堆栈的数据结构有点困惑。本质上的问题是:

"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)

我不明白您将如何收到此输出我尝试编写自己的堆栈结构,但如果我遍历它,我只会先进先出。

如有任何帮助,我将不胜感激。

【问题讨论】:

    标签: data-structures stack


    【解决方案1】:

    没有明确说明,但是查看输入我假设单词被压入堆栈,而- 符号是弹出操作。如果是这样,那么操作是

    • 推送it,堆栈包含it
    • 推送was,栈包含itwas
    • 弹出打印,堆栈包含it
    • 推送the,堆栈包含itthe
    • 推送best,堆栈包含itthebest
    • 流行打印最佳,堆栈包含itthe
    • 推送of,堆栈包含ittheof
    • 推送times,堆栈包含ittheoftimes
    • 弹出打印,堆栈包含ittheof
    • pop prints of,堆栈包含it the;
    • pop 打印 the,堆栈包含 it;
    • 推送it,堆栈包含itit
    • 推送was,堆栈包含ititwas
    • pop prints,堆栈包含itit
    • 推送the,堆栈包含ititthe
    • 弹出打印,堆栈包含itit;
    • 弹出打印,堆栈包含it

    粗体字是pop操作的输出。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多