Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The World Wide Web And Databases International Workshop Webdb 98 Valencia Spain March 27 28 1998 Selected Papers Lncs 1590

Authors: Paolo Atzeni ,Alberto Mendelzon ,Giansalvatore Mecca

1st Edition

3540658904, 978-3540658900

More Books

Students also viewed these Databases questions