Object Oriented Programming assignment @University of Padova, Italy.
Define a template with class
dList<T>
whose objects represent a double linked list for elements of type T. It has to satisfy these costraints:
- memory management without sharing;
dList<T>
has to expose the constructordList(int k, const T& t)
, which builds a list containing k nodes, everyone of which keeps a copy of t;dList<T>
must perform head and tail insertion in a constant time O(1)
void insertFront(const T& t)
: adds a node with infot
to the head and updates the surrounding nodes accordingly;void insertBack(const T& t)
: adds a node with infot
to the tail and updates the surrounding nodes accordingly;
dList<T>
has to expose an overload ofoperator<
which implements the lexicographic sorting;dList<T>
has to expose constant iterator typedList<T>::const_iterator
whose objects allow to iterate through the elements of a list.
To avoid memory leaks with ease, each class' destructor is responsible for deleting its pointers. For instance, the following snipped taken from dNode.h
allows the user to delete a dNode and let the destructor handle the removal of every possible subsequence next to that node.
~dNode() {
if (next != nullptr) {
delete next;
}
}
I've used Visual Studio 2015 to build and run my project. Just double click on DoubleLinkedList.vcxproj
If you prefer using g++, be sure to include the header -std=c++11
.