Problem

As discussed in Chapter 8, the JCF provides an interface for a generic double-ended queue...

As discussed in Chapter 8, the JCF provides an interface for a generic double-ended queue which supports insertion and deletion of items from both the front and back of the data structure. Here is a simplified version of a generic deque interface:

public interface Deque{

boolean isEmpty();

// Return true if the deque is empty, false otherwise.

boolean addFirst(E item);

// Insert the item at the front of the deque. Returns false

// if the item cannot be added to the deque, true otherwise.

boolean addLast(E item);

// Insert the item at the back of the deque. Returns false if

// the item cannot be added to the deque, true otherwise.

boolean contains(Object o);

// Returns true if this deque contains the specified element.

E removeFirst();

// Delete and return the first item in the deque if the deque

// is not empty, otherwise return null (the deque was empty).

E removeLast();

// Delete and return the last item in the deque if the deque

// is not empty, otherwise return null (the deque was empty).

E peekFirst();

// Return the first item in the deque if the deque is

// not empty, leaving the deque unchanged. Otherwise return

// null (the deque was empty).

E peekLast();

// Return the last item in the deque if the deque is

// not empty, leaving the deque unchanged. Otherwise return

// null (the deque was empty).

} // end Deque

a. Create a reference-based implementation of this generic Deque interface.

b. Create an array-based implementation of this generic Deque interface using ArrayList.

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 9
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT