Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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::push_front(const T& data){
}
template
void Sentinel::push_back(const T& data){
}
template
void Sentinel::pop_front(){
}
template
void Sentinel::pop_back(){
}
template
int Sentinel::getData(int data[]) const{
Node* curr=front_->next_;
int numData=0;
while(curr!=back_){
data[numData++]=curr->data_;
curr=curr->next_;
}
return numData;
}
template
int Sentinel::getReverseData(int data[]) const{
Node* curr=back_->prev_;
int numData=0;
while(curr!=front_){
data[numData++]=curr->data_;
curr=curr->prev_;
}
return numData;
}
template
Sentinel::~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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MySQL Crash Course A Hands On Introduction To Database Development

Authors: Rick Silva

1st Edition

1718503008, 978-1718503007

More Books

Students also viewed these Databases questions