Question
GIVEN CODE template class DList { private: struct Node { T data; Node* next; Node* prev; Node(const T& d = T{}, Node* n = nullptr,
GIVEN CODE
template
class DList {
private:
struct Node {
T data;
Node* next;
Node* prev;
Node(const T& d = T{}, Node* n = nullptr, Node* p = nullptr)
: data(d), next(n), prev(p) {}
};
Node* head;
Node* tail;
int sz;
public:
class const_iterator {
public:
const_iterator() : current(nullptr) {}
const T& operator*() const {
return retrieve();
}
const_iterator& operator++() {
current = current->next;
return *this;
}
const_iterator operator++(int) {
const_iterator old = *this;
++(*this);
return old;
}
const_iterator& operator--() {
current = current->prev;
return *this;
}
const_iterator operator--(int) {
const_iterator old = *this;
--(*this);
return old;
}
bool operator==(const const_iterator& rhs) const {
return current == rhs.current;
}
bool operator!=(const const_iterator& rhs) const {
return !(*this == rhs);
}
protected:
Node* current;
const_iterator(Node* p) : current(p) {}
T& retrieve() const {
return current->data;
}
friend class DList
};
class iterator : public const_iterator {
public:
iterator() {}
T& operator*() {
return const_iterator::retrieve();
}
const T& operator*() const {
return const_iterator::operator*();
}
iterator& operator++() {
this->current = this->current->next;
return *this;
}
iterator operator++(int) {
iterator old = *this;
++(*this);
return old;
}
iterator& operator--() {
this->current = this->current->prev;
return *this;
}
iterator operator--(int) {
iterator old = *this;
--(*this);
return old;
}
protected:
iterator(Node* p) : const_iterator(p) {}
friend class DList
};
DList() : head(new Node()), tail(new Node()), sz(0) {
head->next = tail;
tail->prev = head;
}
~DList() {
clear();
delete head;
delete tail;
}
DList(const DList& rhs) : head(new Node()), tail(new Node()), sz(rhs.sz) {
head->next = tail;
tail->prev = head;
for (auto it = rhs.cbegin(); it != rhs.cend(); ++it) {
insert(cend(), *it);
}
}
DList& operator=(const DList& rhs) {
DList copy = rhs;
std::swap(*this, copy);
return *this;
}
DList(DList&& rhs) : head(rhs.head), tail(rhs.tail), sz(rhs.sz) {
rhs.head = nullptr;
rhs.tail = nullptr;
rhs.sz = 0;
}
DList& operator=(DList&& rhs) {
std::swap(head, rhs.head);
std::swap(tail, rhs.tail);
std::swap(sz, rhs.sz);
return *this;
}
iterator insert(iterator it, const T& data) {
Node* p = it.current;
++sz;
return iterator(p)
iterator search(const T& data); iterator erase(iterator it); | |
void sort(iterator first, iterator last); | |
bool empty() const; | |
int size() const; | |
iterator begin(){} | |
iterator end(){} | |
const_iterator cbegin() const{} | |
const_iterator cend() const{} | |
}; | |
template | |
DList | |
} | |
template | |
DList | |
} | |
template | |
DList | |
} | |
template | |
DList | |
} | |
template | |
DList | |
} | |
template | |
DList | |
} | |
template | |
typename DList | |
} | |
template | |
typename DList | |
} | |
template | |
typename DList | |
} | |
template | |
void DList | |
} | |
template | |
bool DList | |
} | |
template | |
int DList | |
There is a given code, please complete the code that is marked in BOLD in C++ code language, than you!
Please provide an answer only for that is marked in BOLD!!
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