Question: IN Java Implement a stack using an array, not an array list. Make your stack size 5 when you test it, but do not hardcode

IN Java

Implement a stack using an array, not an array list.

Make your stack size 5 when you test it, but do not hardcode this!

Implement the following methods in your stack class.

  • stack() creates an empty stacks, stack s is new and empty.
  • push(item) adds a new item to the stack s, stacks is modified.
  • pop() removes and returns an item, stack s is modified.
  • isEmpty() returns a boolean and tests for an empty stacks, stack s is not modified.
  • isFull() returns a boolean and tests for an full stacks, stack s is not modified.
  • size() returns the int size of the stacks, stack s is not modified
  • print() prints the stacks from front to rear, stack s is not modified.
  • top() prints the front element, stack s is not modified.

Write your own Driver file to show that you have implemented all the methods of the stack. A psuedocode example is listed below to guide you. Use print statements as well to show the popped elements, to show the stack after some pushes, to print the size of the stack.

  • push(redShirt)
  • push(greenShirt)
  • push(yellowPants)
  • push(purpleSock)
  • push(pinkSocks)
  • printStack()
  • size()
  • push(blueShirt)
  • size()
  • pop()
  • pop()
  • size()
  • pop()
  • printStack()
  • top()
  • pop()
  • pop()
  • printStack()
  • size()
  • isEmpty()
  • printStack()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!