Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please read the information before TODO import java.lang.reflect.Array; import java.util.Arrays; import java.util.Optional; class NoSuchElementE extends Exception {} public abstract class DequeueArray { protected Optional[] elements;

Please read the information before "TODO" import java.lang.reflect.Array; import java.util.Arrays; import java.util.Optional; class NoSuchElementE extends Exception {} public abstract class DequeueArray { protected Optional[] elements; protected int capacity, front, back, size; // // data stored in locations: // front+1, front+2, ... back-2, back-1 (all mod capacity) // // common cases: // front points to an empty location // back points to an empty location // adding to front decreases 'front' by 1 // adding to back increases 'back' by 1 // removing does the opposite // // |-------------------------| // | 4 5 6 _ _ _ _ _ _ 1 2 3 | // |-------------------------| // /\ /\ /\ // back front capacity // @SuppressWarnings("unchecked") DequeueArray(int initialCapacity) { elements = (Optional[]) Array.newInstance(Optional.class, initialCapacity); Arrays.fill(elements, Optional.empty()); capacity = initialCapacity; front = capacity - 1; back = 0; size = 0; }
public void clear() { elements = (Optional[]) Array.newInstance(Optional.class, 1); Arrays.fill(elements, Optional.empty()); capacity = 1; front = 0; back = 0; size = 0; }
class DequeueArrayDouble extends DequeueArray { DequeueArrayDouble (int initialCapacity) { super(initialCapacity); } /** * Grow the dequeue by doubling its size. * A new array is created, all the elements in the old array * are copied in the first half of the new array */ @SuppressWarnings("unchecked") void grow() { // TODO } }

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_2

Step: 3

blur-text-image_3

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2015 Porto Portugal September 7 11 2015 Proceedings Part 2 Lnai 9285

Authors: Annalisa Appice ,Pedro Pereira Rodrigues ,Vitor Santos Costa ,Joao Gama ,Alipio Jorge ,Carlos Soares

1st Edition

3319235249, 978-3319235240

More Books

Students also viewed these Databases questions