Question
Suppose you wished to use an array to solve a coding problem but the language you are constrained to use (we will call it C--)
Suppose you wished to use an array to solve a coding problem but the language you are constrained to use (we will call it C--) does not support arrays. In other respects, C-- is very similar to C++ and Java. Upon learning something about the syntax of the language, you discover that it does support stacks directly, i.e. you can declare something to be of type stack without defining a stack. Also, push, pop and empty operations are supported as part of the language. You decide to write an array class using a stack as a home for the array. stack S; //Given this declaration itemtype S.pop(); //These are available operations void S.push(itemtype X); void S.empty(); public interface Stack { public int size(); //Returns number of elements in stack public boolean isEmpty(); //Returns true if stack empty, else false public Object peek() //Returns value at top of stack - stack unaltered throws StackEmptyException; public void push(Object element); //Inserts new item at top of stack public Object pop() //Removes and returns item at top of stack throws StackEmptyException; } where public class StackImp implements Stack {...omitted...} You may assume that Object and StackEmptyException are properly defined. There are no intentional syntax errors. Specify the interface for the Array and write the insertion and deletion methods.
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