Question: template class DList{ struct Node{ }; public: 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){}

template
class DList{
struct Node{
};
public:
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{}
};
DList();
~DList();
DList(const DList& rhs);
DList& operator=(const DList& rhs);
DList(DList&& rhs);
DList& operator=(DList&& rhs);
iterator insert(iterator it, const T& data);
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::DList(){
}
template
DList::~DList(){
}
template
DList::DList(const DList& rhs){
}
template
DList& DList::operator=(const DList& rhs){
}
template
DList::DList(DList&& rhs){
}
template
DList& DList::operator=(DList&& rhs){
}
template
typename DList::iterator DList::insert(iterator it, const T& data){
}
template
typename DList::iterator DList::search(const T& data){
}
template
typename DList::iterator DList::erase(iterator it){
}
template
void DList::sort(iterator first, iterator last){
}
template
bool DList::empty() const{
}
template
int DList::size() const{
}

Implement a template for a doubly linked linked list.

The basic class declarations can be found in 'dlist.h'. Please use it as a starting point. You are welcome to add whatever private/protected members you see fit. Nodes in this list will have a pointer not only to the next node but also a pointer to the previous node.

The data type of the data stored in this list (T) supports the following operator:

==

!=

=

< This means that you can use any of the above operators on the data stored in the nodes of your doubly linked list. You do not need to implement these operators. It is up to the program using the doubly linked list to implement these operators for the data type.

The DList class has the following member functions:

DList();

constructor, creates empty DList

iterator insert(iterator it, const T& data);

adds new node containing data before the node refer to by it

function returns iterator to newly added node

iterator begin();

returns iterator to Node containing the first piece of data in the list

iterator end();

returns iterator to the Node after the node containing the last piece of data of the list

const_iterator cbegin() const;

returns const_iterator to to Node containing the first piece of data in the list

const_iterator cend() const;

returns const_iterator to the Node after the node containing the last piece of data of the list

iterator erase(iterator it);

removes the node referred to by it

returns iterator to node that follows the node that was removed

void sort(iterator first, iterator last);

This function sorts all nodes from first to last, including first but not including last. This process must not create any new nodes or deallocate any old nodes. Furthermore, the data within each node is not to be swapped around... the point is to be able to move nodes around to sort. Recreating the list, using temporary arrays to sort or swapping data without moving nodes will be graded as incorrect and you will need to resubmit your assignment if you do this

For example:

In the example below

Initial current list: {1, 3, 4, 8, 2, 4, 7, 3, 6, 5, 9, 10}, suppose that first refers to the node with 8, last refers to the node with 5.

The function would sort the nodes with the bolded values:{1, 3, 4, 8,2,4,7,3,6, 5, 9, 10}

The final list would end up with values in the following order: {1, 3, 4, 2, 3, 4, 6, 7, 8, 5, 9, 10}

iterator search(const T& data);

returns iterator to the node containing data. If data is not found, returns end()

bool empty() const;

function returns true if the list is empty, false otherwise

int size() const;

function returns number of pieces of data stored in the list

~DList(); DList(const DList&); DList& operator=(const DList&); DList(DList&&); DList& operator=(DList&&);

Your sorted linked list must also implement destructor, copy constructor, assignment operator, move constructor, move operator.

Iterator

The idea of an iterator is to provide a means to traverse your class. In the STL, different classes, like vectors or lists have iterators that help you iterate through your list. For the sorted list, you will also write an iterator class.

You will need two iterators. A const_iterator and an iterator which is derived from const_iterator. For both operators, the following public members/operators are required. You are welcome to add any other private or protected members as you see fit:

iterator(); const_iterator();

constructors, returns iterators to nullptrs

iterator operator++(); //prefix ++ iterator operator++(int); //postfix ++ const_iterator operator++(); //prefix ++ const_iterator operator++(int); //postfix ++

prefix and postfix ++ operator

makes iterator point to the next node in the list.

return as appropriate for each operator

iterator operator--(); //prefix -- iterator operator--(int); //postfix -- const_iterator operator--(); //prefix -- const_iterator operator--(int); //postfix -- 

prefix and postfix operator --

increments iterator so that it points to previous node in list

return as appropriate for each operator

bool operator==(const_iterator rhs); - function returns true if rhs and current object refer to the same node bool operator!=(const_iterator rhs); - function returns true if rhs and current object does not refer to the same node
const T& operator*() const; //in const_iterator const T& operator*() const; //in iterator

returns a const reference to data in the node referred to by the iterator.

T& operator*(); 

returns a reference to data in the node referred to by the iterator.

Please answer all the above questions in C++ language, thank you!

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!