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

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!