Results 1 to 3 of 3
- 08-23-2013, 01:10 AM #1
Member
- Join Date
- Aug 2013
- Posts
- 1
- Rep Power
- 0
List 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, 01:16 AM #2
Senior Member
- Join Date
- Jan 2013
- Location
- Northern Virginia, United States
- Posts
- 6,226
- Rep Power
- 15
Re: 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,
JimThe JavaTM Tutorials | SSCCE | Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
- 08-23-2013, 06:15 AM #3
Similar Threads
-
How to pop the element of stack to a list?
By hjxlpp in forum Advanced JavaReplies: 3Last Post: 07-14-2013, 02:10 PM -
Help with stack
By boots9491 in forum New To JavaReplies: 3Last Post: 04-10-2012, 02:59 AM -
Stack Elements
By dougie1809 in forum New To JavaReplies: 15Last Post: 03-26-2012, 06:07 PM -
Stack problem. Object array pushed into stack came out different.
By LoViNgHeArTy in forum New To JavaReplies: 2Last Post: 01-14-2012, 09:56 PM -
Stack Implemented Linked List HELP!!!!!!!!!
By dudedatroz in forum NetBeansReplies: 1Last Post: 02-19-2010, 11:56 PM
Bookmarks