Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started