我正在尝试编写一种从堆栈中弹出k个元素的方法。任何帮助,将不胜感激。

This is what I have tried:
    public void multipop(int k) {
    List l = nil();
    while (true) {
    for(int i =0; i < k; i++) {
    }

最佳答案

将以下概念转换为Java:

create a list to store the popped members in.
while (the stack is not empty and we have to pop more elements) {
    add a popped member from the stack to the list
}
return the list.


完成了

关于java - 我们如何编写一个函数List multiPop(int k)来从堆栈中弹出k个元素,或者直到堆栈为空?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18391686/

10-14 15:39
查看更多