Results 1 to 6 of 6
  1. #1
    coyler_21 is offline Member
    Join Date
    Oct 2010
    Posts
    2
    Rep Power
    0

    Default Implementations of an ArrayStack class

    Hi there I am new to using Java and I was wondering if possible how to complete the implementations of the peek, isEmpty, size, toString and expandCapacity methods for the following code in NetBeans? :confused:

    public class ArrayStack<T> implements StackADT<T>
    {
    /**
    * constant to represent the default capacity of the array
    */
    private final int DEFAULT_CAPACITY = 100;
    /**
    * int that represents both the number of elements and the next
    * available position in the array
    */
    private int top;
    /**
    * array of generic elements to represent the stack
    */
    private T[] stack;
    /**
    * Creates an empty stack using the default capacity.
    */
    public ArrayStack()
    {
    top = 0;
    stack = (T[])(new Object[DEFAULT_CAPACITY]);
    }
    /**
    * Creates an empty stack using the specified capacity.
    * @param initialCapacity represents the specified capacity
    */
    public ArrayStack (int initialCapacity)
    {
    top = 0;
    stack = (T[])(new Object[initialCapacity]);
    }
    /**
    * Adds the specified element to the top of this stack, expanding
    * the capacity of the stack array if necessary.
    * @param element generic element to be pushed onto stack
    */
    public void push (T element)
    {
    if (size() == stack.length)
    expandCapacity();
    stack[top] = element;
    top++;
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  4. #4
    coyler_21 is offline Member
    Join Date
    Oct 2010
    Posts
    2
    Rep Power
    0

    Default No no...

    My boss wants me to try out code for each Implementation to get me used to using NetBeans, I however have not got any knowledge of NetBeans, and I was just looking for a little bit of help!!

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

Similar Threads

  1. Replies: 8
    Last Post: 04-14-2010, 05:49 AM
  2. Replies: 2
    Last Post: 10-01-2009, 11:02 AM
  3. Replies: 7
    Last Post: 05-06-2009, 12:42 PM
  4. Replies: 8
    Last Post: 03-21-2009, 09:34 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
  •