Answered step by step
Verified Expert Solution
Question
1 Approved Answer
This Has To Be Implemented On Java Array Queue Class: /** Implementation of the queue ADT using a fixed-length array. */ public class ArrayQueue implements
This Has To Be Implemented On Java
Array Queue Class:
/** Implementation of the queue ADT using a fixed-length array. */ public class ArrayQueueSafari File Edit View History Bookmarks Window Help (S1% Sat 11:47 AM Q https://mybb.qu.edu.qa/bboswebdav/pid-2371962-dt-content-rid-3145001-2/courses/Spring 2017 CMPS303 21853/HW2.pdf https mybb.qu.edu.qa Reade bbcswebdav/pid-2371962 853/ HNW2.pdf 45001 /courses/Spring 2017 CMPS303 Conten EEE Dropbox C...s Materials Popular Apple Yahoo! Google Maps YouTube Wikipedia News rid-3145001 2/courses/Spring 2017 CM... Assignments algul (Spring 2017 CMPs303 21853 L01 HW 2: Stacks and Queues) Q1) Create class ArrayDegue to implement double ended queue (Deque) Gmodify ueue). De que has the following methods: is Empty0, size0, first0, last0, addFirst0, addLast0, removeFirst0, removeLast0. C10ptsl Test these methods in main method. Q2) Create a java class called DoubleStack to represent a double stack data structure (see figure below). It is like two stacks shared the same array, one from left side and the other one from right side. However, this doesn't mean the array is divided equally between them. It depends on push and pop operations for each one of them. DoubleStack will have SEmptyl, size10, push 1, topl, popl, isEmpty2, size20, push2, top2, and pop2 Write a main0 function to test all the above functionalities. stks: 49 57 3 44 97 23 17 topStk 1 2 topStk2 36 10pts In the main, create an object of DoubleStack, test the methodsimplements Queue { // instance variables public static final int CAPACITY=1000; private E[ ] data; // generic array used for storage private int f = 0; // index of the front element private int sz = 0; // current number of elements // constructors public ArrayQueue( ) { this(CAPACITY); } // constructs queue with default capacity public ArrayQueue(int capacity) { // constructs queue with given capacity data = (E[ ]) new Object[capacity]; // safe cast; compiler may give warning } // methods /** Returns the number of elements in the queue. */ public int size( ) { return sz; } /** Tests whether the queue is empty. */ public boolean isEmpty( ) { return (sz == 0); } /** Inserts an element at the rear of the queue. */ public void enqueue(E e) throws IllegalStateException { if (sz == data.length) throw new IllegalStateException("Queue is full"); int avail = (f + sz) % data.length; // use modular arithmetic data[avail] = e; sz++; } /** Returns, but does not remove, the first element of the queue (null if empty). */ public E first( ) { if (isEmpty( )) return null; return data[f]; } /** Removes and returns the first element of the queue (null if empty). */ public E dequeue( ) { if (isEmpty( )) return null; E answer = data[f]; data[f] = null; // dereference to help garbage collection f = (f + 1) % data.length; sz--; return answer; } }
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