How can we write a function List multiPop(int k) that pops k elements from the stack or until the stack is empty?

so far I have tried: public void multipop(int k) {

while (top != null) {

for(int i =0; i < k; i++) {

this.pop();

}

}

}

Printable View

- 08-23-2013, 12:10 AMgreenday89List multiPop(int k) that pops k elements from the stack or until the stack is empty.
How can we write a function List multiPop(int k) that pops k elements from the stack or until the stack is empty?

so far I have tried: public void multipop(int k) {

while (top != null) {

for(int i =0; i < k; i++) {

this.pop();

}

}

} - 08-23-2013, 12:16 AMjim829Re: List multiPop(int k) that pops k elements from the stack or until the stack is em
What is top? And since you are apparently not keeping any of the values it is not necessary to pop anything. Just use the value of k to reset the index of the stack. This does make an assumption on how the stack is implemented.

Regards,

Jim - 08-23-2013, 05:15 AMDarrylBurkeRe: List multiPop(int k) that pops k elements from the stack or until the stack is em
Moved from Advanced Java. Please confine homework questions to the New to Java section.

db