Results 1 to 3 of 3
  1. #1
    greenday89 is offline Member
    Join Date
    Aug 2013
    Posts
    1
    Rep Power
    0

    Default 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();
    }
    }
    }

  2. #2
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,418
    Rep Power
    5

    Default 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,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,184
    Rep Power
    19

    Default Re: 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
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. How to pop the element of stack to a list?
    By hjxlpp in forum Advanced Java
    Replies: 3
    Last Post: 07-14-2013, 01:10 PM
  2. Help with stack
    By boots9491 in forum New To Java
    Replies: 3
    Last Post: 04-10-2012, 01:59 AM
  3. Stack Elements
    By dougie1809 in forum New To Java
    Replies: 15
    Last Post: 03-26-2012, 05:07 PM
  4. Replies: 2
    Last Post: 01-14-2012, 08:56 PM
  5. Stack Implemented Linked List HELP!!!!!!!!!
    By dudedatroz in forum NetBeans
    Replies: 1
    Last Post: 02-19-2010, 10:56 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •