This section is a reference guide to classes/interfaces built by API on top of List abstract data type:
Advantages and disadvantages of each data structure as List implementation are described in great detail by this section. Please review it carefully in order to decide which solution suits your business needs!
To see how can above classes be iterated, please review iterators section. To see a real life example how can above classes be used, please have a look at unit tests.
Interface that defines operations one can perform on a List abstract data type
template <typename T>
class List
Method | Signature | Description |
~List | virtual ~List () | Deletes elements inside from heap memory |
operator[] | virtual const T& operator[] (const std::size_t& index) const = 0 | Gets element in list by position |
clear | virtual void clear () = 0 | Clears list of all elements |
addToHead | virtual void addToHead (const T& value) = 0 | Adds element to end of list |
addToTail | virtual void addToTail (const T& value) = 0 | Adds element to start of list |
get | virtual const T& get (const std::size_t& index) const = 0 | Gets element in list by position |
set | virtual void set (const std::size_t& index, const T& value) = 0 | Sets value of element in list by position |
emplace | virtual void emplace (const std::size_t& index, const T& value) = 0 | Appends element to list after position |
isEmpty | virtual bool isEmpty () const = 0 | Checks if list is empty |
size | virtual const std::size_t& size () const = 0 | Gets number of elements in list |
containsIndex | virtual bool containsIndex (const std::size_t& index) const = 0 | Checks if list contains a position |
containsValue | virtual bool containsValue (const T& value) const = 0 | Checks if list contains a value |
removeIndex | virtual void removeIndex (const std::size_t& index) = 0 | Removes element in list by position |
removeValue | virtual void removeValue (const T& value) = 0 | Removes element in list by value |
begin | virtual ListIterator<T>* begin () = 0 | Returns an iterator to the first element of list |
end | virtual ListIterator<T>* end () = 0 | Returns an iterator to the element following last element of list |
Class that implements Dynamic Array data structure on top of List abstract data type
template <typename T, int (*comparator)(const T&, const T&) = comparator<T>>
class ArrayList : public List<T>
Method | Signature | Description |
ArrayList | ArrayList () | Constructs a Dynamic Array of unknown initial size |
ArrayList | ArrayList (const std::size_t& reservedSize) | Constructs a Dynamic Array of known size |
sort | void sort (bool (*comparator) (const T&, const T&)) | Sorts elements inside list according to comparator |
Class that implements Linked List data structure on top of List abstract data type
template <typename T, int (*comparator)(const T&, const T&) = comparator<T>>
class LinkedList : public List<T>
Method | Signature | Description |
LinkedList | LinkedList () | Constructs a Linked List |
sort | void sort (bool (*comparator) (const T&, const T&)) | Sorts elements inside list according to comparator |
Class that implements Doubly Linked List data structure on top of List abstract data type
template <typename T, int (*comparator)(const T&, const T&) = comparator<T>>
class DoublyLinkedList : public List<T>
Method | Signature | Description |
DoublyLinkedList | DoublyLinkedList () | Constructs a Doubly Linked List |
sort | void sort (bool (*comparator) (const T&, const T&)) | Sorts elements inside list according to comparator |