Results 1 to 4 of 4

Thread: MyStack

  1. #1
    mdavda909 is offline Member
    Join Date
    Apr 2014
    Posts
    5
    Rep Power
    0

    Default MyStack

    Hi,
    I need some help with my code, We have to create a program called MyStack.
    In Push: Add one element at the end of the buffer.
    In Pull: Remove one element from the end of the buffer.
    In isEmpty: Should check if the list is empty or not and return the result as a boolean variable.
    I am totally confused, I wrote the buffer and the array, but how do i add an remove element from the buffer?
    How do i add an element? What Statement do i Use?
    Please Help!
    Java Code:
    public class MyStack<T> implements Stack<T> {
        private final T[] ringbuffer;
        int index = 0;
        int last;
    
        @SuppressWarnings({ "unchecked" })
        public MyStack(final int size) {
            ringbuffer = (T[]) new Object[size];
        }
    
        @Override
        public final boolean isEmpty () {
            // TODO Auto-generated method stub
            return false;
        }
    
        @Override
        public final T pop () throws BufferEmptyException {
            // TODO Auto-generated method stub
            return null;
        }
    
        @Override
        public void push (final T item) throws BufferFullException {
            // TODO Auto-generated method stub
      
        }
    
        public static void main () {
            System.out.println("The Stack is empty");
            System.out.println("The Stack is Full");
        }
    }

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,963
    Rep Power
    8

    Default Re: MyStack

    How would you go about adding an element to an array?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    mdavda909 is offline Member
    Join Date
    Apr 2014
    Posts
    5
    Rep Power
    0

    Default Re: MyStack

    I Would use
    Array[i] = number;

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,963
    Rep Power
    8

    Default Re: MyStack

    Your buffer is an array. To add an element to the buffer, you just add an element to the array.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

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
  •