Question: class Sentinel{ struct Node{ T data_; Node* next_; Node* prev_; Node(const T& data=T{},Node* next=nullptr, Node* prev=nullptr){ data_=data; next_=next; prev_=prev; } }; Node* front_; Node* back_;
| class Sentinel{ | |
| struct Node{ | |
| T data_; | |
| Node* next_; | |
| Node* prev_; | |
| Node(const T& data=T{},Node* next=nullptr, Node* prev=nullptr){ | |
| data_=data; | |
| next_=next; | |
| prev_=prev; | |
| } | |
| }; | |
| Node* front_; | |
| Node* back_; | |
| public: | |
| Sentinel(){ | |
| front_=new Node(); | |
| back_=new Node(); | |
| front_->next_=back_; | |
| back_->prev_=front_; | |
| } | |
| void push_front(const T& data); | |
| void push_back(const T& data); | |
| void pop_front(); | |
| void pop_back(); | |
| int getData(int data[]) const; | |
| int getReverseData(int data[]) const; | |
| ~Sentinel(); | |
| }; | |
| template | |
| void Sentinel | |
| } | |
| template | |
| void Sentinel | |
| } | |
| template | |
| void Sentinel | |
| } | |
| template | |
| void Sentinel | |
| } | |
| template | |
| int Sentinel | |
| Node* curr=front_->next_; | |
| int numData=0; | |
| while(curr!=back_){ | |
| data[numData++]=curr->data_; | |
| curr=curr->next_; | |
| } | |
| return numData; | |
| } | |
| template | |
| int Sentinel | |
| Node* curr=back_->prev_; | |
| int numData=0; | |
| while(curr!=front_){ | |
| data[numData++]=curr->data_; | |
| curr=curr->prev_; | |
| } | |
| return numData; | |
| } | |
| template | |
| Sentinel | |
| } |
Complete the push_front(), push_back(), pop_front(),pop_back() and destructor functions for Sentinel class.
Please answer the above question in C++ code language, thank you!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
