Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import jsjf.exceptions.*; public class CircularArrayQueue implements QueueADT { private final static int DEFAULT_CAPACITY = 100; private int front, rear, count; private T[] queue; public CircularArrayQueue

import jsjf.exceptions.*;

public class CircularArrayQueue implements QueueADT { private final static int DEFAULT_CAPACITY = 100; private int front, rear, count; private T[] queue; public CircularArrayQueue (int initialCapacity) { front = rear = count = 0; queue = (T[]) (new Object[initialCapacity]); } public CircularArrayQueue() { this(DEFAULT_CAPACITY); } public void enqueue(T element) { if (size() == queue.length) expandCapacity(); queue[rear] = element; rear = (rear+1) % queue.length; count++; } private void expandCapacity() { T[] larger = (T[]) (new Object[queue.length *2]); for (int scan = 0; scan < count; scan++) { larger[scan] = queue[front]; front = (front + 1) % queue.length; } front = 0; rear = count; queue = larger; } public T dequeue() throws EmptyCollectionException { if (isEmpty()) throw new EmptyCollectionException("queue"); T result = queue[front]; queue[front] = null; front = (front+1) % queue.length; count--; return result; } public T first() throws EmptyCollectionException { if (isEmpty()) throw new EmptyCollectionException ("queue"); T result = queue[front]; return result; // To be completed as a Programming Project } public boolean isEmpty() { return (count == 0); } public int size() { return count; } public String toString() { String queueElements = ""; for(int i = 0; i < rear; i++) { if(queue[i] != null) { queueElements = queueElements + queue[i].toString() + " "; } } return queueElements; } }

public class LinearNode { private LinearNode next; private T element; public LinearNode() { next = null; element = null; } public LinearNode(T elem) { next = null; element = elem; } public LinearNode getNext() { return next; } public void setNext(LinearNode node) { next = node; } public T getElement() { return element; } public void setElement(T elem) { element = elem; } }

How to create a DropoutCircularArrayQueue Class, which has a fixed size and drops out the oldest item in the queue if the queue becomes full.Create a DropoutCircularArrayQueue Class, which has a fixed size and drops out the oldest item in the queue if the queue becomes full.

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

Advances In Databases And Information Systems 14th East European Conference Adbis 2010 Novi Sad Serbia September 2010 Proceedings Lncs 6295

Authors: Barbara Catania ,Mirjana Ivanovic ,Bernhard Thalheim

2010th Edition

3642155758, 978-3642155758

More Books

Students also viewed these Databases questions