Answered step by step
Verified Expert Solution
Question
1 Approved Answer
#include template class DList{ 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_;
#include | |
template | |
class DList{ | |
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: | |
DList(){ | |
front_=nullptr; | |
back_=nullptr; | |
} | |
void push_front(const T& data); | |
~DList(); | |
class const_iterator{ | |
Node* curr_; | |
const_iterator(Node* n){ | |
curr_=n; | |
} | |
public: | |
const_iterator(){ | |
curr_=nullptr; | |
} | |
const_iterator& operator++(){} | |
const_iterator operator++(int){} | |
const_iterator& operator--(){} | |
const_iterator operator--(int){} | |
bool operator==(const_iterator rhs){} | |
bool operator!=(const_iterator rhs){} | |
const T& operator*()const{} | |
}; | |
class iterator:public const_iterator{ | |
public: | |
iterator(); | |
iterator& operator++(){} | |
iterator operator++(int){} | |
iterator& operator--(){} | |
iterator operator--(int){} | |
T& operator*(){} | |
const T& operator*()const{} | |
}; | |
const_iterator cbegin() const{ } | |
iterator begin(){ } | |
const_iterator cend() const{} | |
iterator end(){} | |
}; | |
template | |
void DList | |
**YOUR CODE** | |
} | |
template | |
DList | |
**YOUR CODE** | |
} | |
template | |
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); | |
~Sentinel(); | |
class const_iterator{ | |
public: | |
const_iterator(){} | |
const_iterator& operator++(){} | |
const_iterator operator++(int){} | |
const_iterator& operator--(){} | |
const_iterator operator--(int){} | |
bool operator==(const_iterator rhs){} | |
bool operator!=(const_iterator rhs){} | |
const T& operator*()const{} | |
}; | |
class iterator:public const_iterator{ | |
public: | |
iterator(); | |
iterator& operator++(){} | |
iterator operator++(int){} | |
iterator& operator--(){} | |
iterator operator--(int){} | |
T& operator*(){} | |
const T& operator*()const{} | |
}; | |
const_iterator cbegin() const{} | |
iterator begin(){} | |
const_iterator cend() const{} | |
iterator end(){} | |
}; | |
template | |
void Sentinel | |
**YOUR CODE** | |
} | |
template | |
Sentinel | |
**YOUR CODE** | |
} |
To support this add the following functions to each of DList and Sentinel classes:
iterator begin(); const_iterator cbegin() const;
These functions returns an iterator/const_iterator to the first node in the list, end() if list is empty.
iterator end(); const_iterator cend() const;
these functions returns an iterator/const_iterator to the node just after the last node in the linked list.
Please implement iterator and const_iterator for functions DList and Sentinel classes in C++ code language, thank you!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started