Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Very Easy Java Question!! Implement the prepend() and popRear() methods in the following CircularDeque class, which uses a circular array to store the elements. public

Very Easy Java Question!!

Implement the prepend() and popRear() methods in the following CircularDeque class, which uses a circular array to store the elements.

public class CircularDeque { private Object [] array; private int front; private int size;

/* Build a circular array-based deque with specified capacity * @param: int capacity : size of the array to use */ public CircularDeque(int capacity) { array = new Object[capacity]; }

/* if deuque is not full, append element e to the deque and return true, * otherwise return false * @param: T e : Element of type e to appended to the dequee * @return: true if append successful and false otherwise */ public boolean append(T e) { if (size == array.length) { return false; } array[(front + size) % array.length] = e; size++; return true; }

/* if deuque is not full, prepend element e to the deque and return true, * otherwise return false * @param: T e : Element of type e to prepended to the dequee * @return: true if prepend successful and false otherwise */ public boolean prepend(T e) { // WRITE code here (see append() above for hints) return true; }

/* if deuque is not empty, remove and return the element at the front of the * deque, else return null * @return: element of type T if deque was not empty, else null */ public T popFront() { T e = null; if (size > 0) { e = (T)array[front]; front = (front + 1) % array.length; size--; } return e; }

/* if deuque is not empty, remove and return the element at the front of the * deque, else return null * @return: element of type T if deque was not empty, else null */ public T popRear() { T e = null; // WRITE code here (see popFront() above for hints)

return e; } /* returns true if empty and false otherwise * @return: boolean true if empty */ public boolean isEmpty() { return size == 0; } }

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

Formal SQL Tuning For Oracle Databases Practical Efficiency Efficient Practice

Authors: Leonid Nossov ,Hanno Ernst ,Victor Chupis

1st Edition

3662570564, 978-3662570562

More Books

Students also viewed these Databases questions