Question: use doubly linked list to implement a deque data type. complete Deque.cpp Deque.cpp #include #include deque.h using namespace std; Deque::Deque() { head = nullptr; tail

use doubly linked list to implement a deque data type.

complete Deque.cpp

Deque.cpp

#include  #include "deque.h" using namespace std; Deque::Deque() { head = nullptr; tail = nullptr; count = 0; } // Add the new Node to the front of linked list, Check is the deque is empty or not and update the head, tail and etc properly void Deque::push_front(string s) { // TO DO } // Add the new Node to the end of linked list,Check is the deque is empty or not and update the head, tail and etc proporly void Deque::push_back(string s) { // TO DO } //check if this is the last element. when you update the links and head, don't forget to release the memory void Deque::pop_front() { // TO DO } //check if this is the last element. when you update the links and tail, don't forget to release the memory void Deque::pop_back() { // TO DO } //return the information of the front node , if it is an empty deque return "" string Deque::front() { // TO DO } //return the infromation of the back node, if it is an empty deque return "" string Deque::back() { // TO DO } int Deque::size() { return count; } 

Deque.h

#ifndef DEQUE_H #define DEQUE_H #include  using namespace std; class Deque { public: Deque(); void push_back(string s); void pop_back(); string back(); void push_front(string s); void pop_front(); string front(); int size(); private: class Node { public: string s; Node* next; Node* prev; }; Node* head; Node* tail; int count; }; #endif 

Source.cpp

#include "Deque.h" #include  using namespace std; int main() { Deque dq = Deque(); dq.push_front("CSI"); dq.push_back("CSII"); dq.push_back("CSIII"); dq.push_front("Network"); dq.pop_back(); cout << dq.back() << endl; cout << dq.front() << endl; dq.pop_front(); cout << dq.back() << endl; cout << dq.front() << endl; /** The output should be CSII Network CSII CSI */ return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!