Question

In: Computer Science

A deque (short for double-ended queue, but pronounced “deck”) is an abstract data type that supports...

A deque (short for double-ended queue, but pronounced “deck”) is an abstract data type that supports adding and removing at both the front and back. So, at a bare minimum, a deque has four operations: addFront(), removeFront(), addBack(), removeBack(). Suppose you have a deque D containing the numbers (1, 2, 3, 4, 5, 6, 7, 8), in this order. Suppose further that you have an initially empty queue Q. Give pseudo-code description of a method that uses only D and Q (and no other variables or objects) and results in D storing the elements (1, 2, 3, 5, 4, 6, 7, 8), in this order.

Solutions

Expert Solution

Simple pseudocode to make D = (1, 2, 3, 5, 4, 6, 7, 8)

Note: Please forgive if this is not in the required format, I’m just providing you step by step solution to implement this, then you can easily convert this into any format you like.

Initially Dequeue D contains: (1, 2, 3, 4, 5, 6, 7, 8)

Initially Queue Q contains: ()

Loop for 5 times, call removeFront() in D, enqueue the removed element to Q

D becomes (6,7,8)

Q becomes (1,2,3,4,5)

Loop for 3 times, call dequeue() in Q, pass the removed value to addBack() in D

D becomes (6,7,8,1,2,3)

Q becomes (4,5)

Loop for 2 times, Call dequeue() in Q, pass the removed value to addFront() in D

D becomes (5,4,6,7,8,1,2,3)

Q becomes ()

Loop for 3 times, Call removeBack() in D, pass the removed element to addFront() in D

D becomes (1,2,3,5,4,6,7,8)

Q becomes ()

Let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks


Related Solutions

Study and implement data structure deque (double ended queue, pronounced as "deck"). IN C++ PLEASE
Study and implement data structure deque (double ended queue, pronounced as "deck"). IN C++ PLEASE
1. A double-ended queue, or deque, is a data structure consisting of a list of items...
1. A double-ended queue, or deque, is a data structure consisting of a list of items on which the following operations are defined: addToBack(x): insert item x on the back end of the queue addToFront(x): insert item x on the front end of the queue getBack(): returns the element on the back end of the queue getFront(): returns the element on the front end of the queue removeBack(): remove the back item from the queue removeFront(): remove the front item...
A deque (pronounced deck) is an ordered set of items from which items may be deleted...
A deque (pronounced deck) is an ordered set of items from which items may be deleted at either end and into which items may be inserted at either end. Call the two ends left and right. This is an access-restricted structure since no insertions or deletions can happen other than at the ends. Implement a deque as a doubly-linked circular list with a header. Write InsertRight and DeleteLeft.
Create a Deque class based on the following description of deque (double-ended queues). A dequeue is...
Create a Deque class based on the following description of deque (double-ended queues). A dequeue is a double-ended queue. You can insert items at either end and delete them from either end. Therefore, the deque offers two insert operations and two remove operations: insertLeft() and insertRight() removeLeft() and removeRight(). Deques may also have "peek" methods ( peekLeft() and peekRight() )that let you see the left or right item in the deque without remove the item from the deque. For this...
Give a pseudo-code description for an array-based implementation of the deque ADT (Abstract Data Type). What...
Give a pseudo-code description for an array-based implementation of the deque ADT (Abstract Data Type). What is the running time for each operation?
A max-heap can be used as a max-priority queue, which is an abstract data type having...
A max-heap can be used as a max-priority queue, which is an abstract data type having the operations Insert, Maximum, Extract-Max, and Increase-Key. a. Describe how to implement a FIFO queue with a priority queue, and analyze the time complexity of the implementation (Insert and Delete operations), assuming that a heap is used for the priority queue. b. Describe how to implement a LIFO queue (i.e. a stack) with a priority queue, and analyze the time complexity of the implementation...
Using the linked list abstract data type “Queue ADT”, write a menu dirven user interfece to...
Using the linked list abstract data type “Queue ADT”, write a menu dirven user interfece to teach each of the operations in the ADT. Any errors discovered during the processing should be printed as a part of the test result. Please Use C++ language.
java method for dequeue write the “dequeue” method for a queue of type double. If the...
java method for dequeue write the “dequeue” method for a queue of type double. If the queue is empty return 0.0. Make sure to change the links properly ensure that the data structure remains a queue. use the code provided below public class Q04 { public class ListNode//Public for testing purposes { public double data; public ListNode link; public ListNode(double aData, ListNode aLink) { data = aData; link = aLink; } } public ListNode head;//Public for testing purposes public ListNode...
/** * Interface for a set data type that supports adding, removing and contains operations. *...
/** * Interface for a set data type that supports adding, removing and contains operations. * @param <T> the type parameter for the elements of the set */ interface SetADT<T> { /** * Add a new element to the set. * @param el the new element to add to the set * @return true if the element has been added to the set, false if it was already in the set * @throws IllegalArgumentException if the new element passed to...
These questions are about an abstract data type for sets of integers. The representation used will...
These questions are about an abstract data type for sets of integers. The representation used will be sorted lists without duplicates. To help answer the questions, the following pseudocode of merge-sort for lists may be useful. It is assumed head(x) and tail(x) return the head (first element) and tail (remaining elements) of a list, respectively, and a procedure is available for splitting a list into two lists of approximately equal size. // returns sorted version of list x mergesort(x):        ...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT