How to sort a stack using only Push, Pop, Top, IsEmpty, IsFull?

前端 未结 10 2023
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-06 09:26

Given a stack S, need to sort the stack using only Push, Pop, Top, IsEmpty, IsFull.

Looking for most sim

10条回答
  •  一向
    一向 (楼主)
    2021-02-06 09:56

    To bad you couldn't have two other stacks, then you could have played the Towers of Hanoi in O(n) space.

提交回复
热议问题