Question: Implement the Stack and Queue interfaces with a unique class that is derived from class LinkedDeque (Code Fragment 5.21). Data from in Code Fragment 5.21
Implement the Stack and Queue interfaces with a unique class that is derived from class LinkedDeque (Code Fragment 5.21).
Data from in Code Fragment 5.21
The class structure for class LinkedDeque.
We have not bothered to provide an explicit destructor, because the DLinkedList class provides its own destructor, which is automatically invoked when our Linked-Deque structure is destroyed. Most of the member functions for the LinkedDeque class are straightforward generalizations of the corresponding functions of the LinkedQueue class, so we have omitted them. In Code Fragment 5.22, we present the implementations of the member functions for performing insertions and removals of elements from the deque. Observe that, in each case, we simply invoke the appropriate operation from the underlying DLinkedList object.

void Linked Deque::insertFront (const Elem& e) { D.addFront(e); n++; } void Linked Deque::insertBack(const Elem& e) { D.addBack(e); n++; // insert new first element } } void Linked Deque::removeFront() throw (DequeEmpty) { if (empty()) throw DequeEmpty("removeFront of empty deque"); D.removeFront(); n--; // insert new last element n--; } void Linked Deque::removeBack() throw (DequeEmpty) { if (empty()) throw DequeEmpty("removeBack of empty deque"); D.removeBack(); // remove first element // remove last element
Step by Step Solution
3.44 Rating (167 Votes )
There are 3 Steps involved in it
The Stack and Queue interfaces are implemented with a unique class that is derived from class Linked... View full answer
Get step-by-step solutions from verified subject matter experts
