Question
in java In this assignment, you are going to use queue to implement stack. It is certainly not effective way to implement the ADT, but
in java
In this assignment, you are going to use queue to implement stack. It is certainly not effective way to implement the ADT, but it is a good example to apply what you have learnt from this class to design new ADT. Please read documents carefully and perform the following tasks: Create a file name NumberStack.java then copy the code from NumberStack.txt Implement the methods related to stack operations. You are NOT allowed to add any data members to this class. Once completed, write a driver program named App.java to test your implementation of the Stack ADT
Given files:
IntegerQueue.txt
public class IntegerQueue implements IntegerQueueInterface{
private Integer[] data; private int numberOfElements=0; private int front=0,rear=-1; public IntegerQueue(int cap){ data=new Integer[cap]; }
public void enqueue(Integer val){ if(!isFull()){ rear =(rear+1) % data.length; data[rear]=val; numberOfElements++; } } public Integer peek(){ if(!isEmpty()){ return data[front]; } return null; } public Integer dequeue(){ Integer tmp=null; if(!isEmpty()){ tmp=data[front]; front = (front+1) % data.length; numberOfElements--; } return tmp; } public int size(){ return numberOfElements; } public boolean isEmpty(){ return numberOfElements==0; } public boolean isFull(){ return numberOfElements == data.length; } }
NumberStack.txt
public class NumberStack{ private IntegerQueue q1; private IntegerQueue q2; public NumberStack(int cap){ } public int size(){ } public boolean isEmpty(){ } public boolean isFull(){ } public void pop(){ } public void push(int data){ } public Integer top(){ } }
update: Create a file name NumberStack.java then copy the ENTIRE code from NumberStack.txt to NumberStack.java. then we have to implement methods related to the stack operations.
Once completed, write a driver program named App.java to test your implementation of the Stack ADT
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