X1222: Double Ended Queue: Deque A double ended queue, known as deque, is a queue data structure that allows adding and removing elements from both ends of the queue. Instead of enqueue and dequeue, it has insert, delete, and get for both front and last of the queue as shown below. The data stored internally is stored in a ListNodesPlus object. The basic class definition is shown below: public class Deque { private ListNodePlus elements; // code ommitted for space public void clear() {...}; public int numElements () {...}; public boolean isEmpty() {...}; // Implement the following four methods public void insertFront (E it) { } public E deleteFront () { } public void insertLast (E it) { } public E deleteLast() { } Write the following four methods: • insertFront (E it) takes it and adds it to the front of the queue. stored internally in elements. The front of the queue is defined as position 0 in the queue. • deleteFront () removes the element at the front of the queue and returns it. insertLast (E it) takes it and adds it to the back (last position) of the queue stored internally. The back of the queue is defined as the last element in the queue. deleteLast() removes the element at the end of the queue and returns it.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter18: Stacks And Queues
Section: Chapter Questions
Problem 3PE
icon
Related questions
Question
X1222: Double Ended Queue: Deque
A double ended queue, known as deque, is a queue data structure that allows adding and removing elements from both ends of the queue. Instead of enqueue and dequeue, it
has insert, delete, and get for both front and last of the queue as shown below.
The data stored internally is stored in a ListNodesPlus object. The basic class definition is shown below:
public class Deque<E> {
private ListNodePlus<E> elements;
// code ommitted for space
public void clear() {...};
public int numElements () {...};
public boolean isEmpty() {...};
●
// Implement the following four methods
public void insertFront (E it) { }
public E deleteFront () { }
public void insertLast (E it) { }
public E deleteLast() { }
Write the following four methods:
• insertFront (E it) takes it and adds it to the front of the queue. stored internally in elements. The front of the queue is defined as position 0 in the queue.
● deleteFront () removes the element at the front of the queue and returns it.
● insertLast (E it) takes it and adds it to the back (last position) of the queue stored internally. The back of the queue is defined as the last element in the queue.
deleteLast() removes the element at the end of the queue and returns it.
Transcribed Image Text:X1222: Double Ended Queue: Deque A double ended queue, known as deque, is a queue data structure that allows adding and removing elements from both ends of the queue. Instead of enqueue and dequeue, it has insert, delete, and get for both front and last of the queue as shown below. The data stored internally is stored in a ListNodesPlus object. The basic class definition is shown below: public class Deque<E> { private ListNodePlus<E> elements; // code ommitted for space public void clear() {...}; public int numElements () {...}; public boolean isEmpty() {...}; ● // Implement the following four methods public void insertFront (E it) { } public E deleteFront () { } public void insertLast (E it) { } public E deleteLast() { } Write the following four methods: • insertFront (E it) takes it and adds it to the front of the queue. stored internally in elements. The front of the queue is defined as position 0 in the queue. ● deleteFront () removes the element at the front of the queue and returns it. ● insertLast (E it) takes it and adds it to the back (last position) of the queue stored internally. The back of the queue is defined as the last element in the queue. deleteLast() removes the element at the end of the queue and returns it.
Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Operations of Linked List
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning