且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将堆栈的值分配给另一个堆栈

更新时间:2021-07-24 22:24:33

接口看起来有点偏。让我们从那里开始,看看是否让你超过了你的驼峰。

Your interfaces look a bit off. Let's start there and see if that gets you over your hump.

stack.top()项目,但不会删除它。这对于从一个堆栈转移到另一个堆栈似乎没有用。您已经有了isEmptyStack()来检查顶层元素是否存在。

stack.top() usually peeks at an item, but doesn't remove it. This doesn't seem useful for transfering from one stack to anther. You already have isEmptyStack() to check that the top element exists.

stack.pop()从堆栈的顶部项目。这听起来对传输有用。

stack.pop() usually takes the top item from a stack. This sounds useful for transferring.

stack.push(item)将项目放在堆栈顶部。这听起来对转移有用。

stack.push(item) places item onto the top of the stack. This sounds useful for transferring.

stack.push()看起来错了。推送什么?

stack.push() just seems wrong. Push what?

希望实现这些方法后,其余部分将从您提供的问题的英语描述开始有意义。

Hopefully, once you implement these methods, the rest will start to make sense from the english description of the problem you provided.

更新:这是你想要的:

|a  |   |     |   |   |     |   |   |     |   |c  |
|b  |   |     |b  |   |     |   |b  |     |   |b  |
|c  |   |     |c  |a  |     |c  |a  |     |   |a  |
1   tmp 2     1   tmp 2     1   tmp 2     1   tmp 2

|   |   |     |   |   |     |   |   |a
|   |b  |     |   |   |b    |   |   |b
|   |a  |c    |   |a  |c    |   |   |c
1   tmp 2     1   tmp 2     1   tmp 2 

pop,和IsEmptyStack,没有相互分配堆栈(这种做法失败了分配的目的),你能这样做吗?

Now, with just push, pop, and IsEmptyStack, with no assigning of stacks to one another (that sort of defeats the purpose of the assignment), can you do this?