我正在尝试编写一个从堆栈中弹出 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.
完毕
list multipop(int k, list stack){
int increment = 0;
while(stack.next() != null && k < increment){
stack.pop();
increment++;
}
}
return stack;
我正在排序假设您已经创建了方法 .next() 和 .pop() 。