Results 1 to 2 of 2

Thread: Stack

  1. #1
    billjohn2 is offline Member
    Join Date
    Oct 2012
    Rep Power

    Default Stack


    Can you create a Stack class without any packages? How would you do that?

    I know you can be using:
    import java.util.*;

    But how can you create entire Stack class yourself?

    Thank you! And sorry for poor english. :)

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    New Zealand
    Rep Power

    Default Re: Stack

    But how can you create entire Stack class yourself?
    First, think about and write down a comprehensive (complete) and precise (exact) description of what your class will do. As is often the case in computing Wikipedia is a big help. In particular, decide what operations you will be implementing and what type of thing will be contained in the stack (int, String, Object) and whether or not you intend using generics.

    The precise wording of the question you were given will be a help here. But I can't emphasise enough how important it is to have a "game plan" - a comprehensive and precise notion of what you are doing - before you start coding (ie working on the how of the problem). That way can you can avoid getting lost or becoming overwhelmed.


    In one sense the question on how you implement a stack adt in Java without any of the standard libraries is straight forward: the only "built in" data structure you have is an array. So the state of your Stack class is going to include an array which might have to be reassigned so it can become bigger. The operations you have decided to implement will involve working with that array: adding/moving/removing elements.


    Since you are implementing the Stack class yourself, I assume you are not after anyone here to write the code for you. But do post code and ask specific questions about it, if you can't understand compiler messages or if the runtime behaviour of your code is not what you expect or intend.

    If the Wikipedia article, or your textbook etc, is unclear and you are left without a very clear idea of what a Stack is then post what is unclear and ask about that.
    Last edited by pbrockway2; 10-03-2012 at 01:38 AM.

Similar Threads

  1. Help with stack
    By boots9491 in forum New To Java
    Replies: 3
    Last Post: 04-10-2012, 01:59 AM
  2. Replies: 2
    Last Post: 01-14-2012, 08:56 PM
  3. need stack help
    By ali1 in forum New To Java
    Replies: 4
    Last Post: 11-05-2011, 08:48 PM
  4. Stack
    By kayln in forum Eclipse
    Replies: 0
    Last Post: 03-04-2011, 08:14 PM
  5. How big is the stack??
    By mgeno216 in forum New To Java
    Replies: 6
    Last Post: 03-04-2011, 08:04 AM

Posting Permissions

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