Question: (in java) In this assignment, you are going to use stacks to implement queue. Please read documents carefully and perform the following tasks: Create a

(in java) In this assignment, you are going to use stacks to implement queue. Please read documents carefully and perform the following tasks: Create a file name NumberQueue.java then copy the code from NumberQueue.txt Implement the methods related to queue 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 Queue ADT

Given files:

NumberQueue.txt (which will be copied to NumberQueue.java):

public class NumberQueue{ private NumberStack s1; private NumberStack s2; private int cap; public NumberQueue(int cap){ this.cap=cap; s1=new NumberStack(cap); s2=new NumberStack(cap); } public int size(){ } public boolean isEmpty(){ } public boolean isFull(){ } public void enqueue(int data){//if full, do nothing } public void dequeue(){ } }

NumberStack.txt:

public class NumberStack{ private int[] data; private int index= -1; public NumberStack(int cap){ data=new int[cap]; } public boolean isEmpty(){ return index == -1; } public boolean isFull(){ return index==data.length-1; } public int size(){ return index+1; } public int top(){ if(!isEmpty()){ return data[index]; }else{ return Integer.MIN_VALUE; } } public void push(int num){ if(!isFull()){ data[++index]=num; } } public void pop(){ if(!isEmpty()){ index--; } } }

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!