diff options
Fully documented generic classes
1 files changed, 24 insertions, 5 deletions
| -rw-r--r-- | src/Generic/List/OrderedList.hpp | 29 |
diff --git a/src/Generic/List/OrderedList.hpp b/src/Generic/List/OrderedList.hpp index 069bd4a..8d13a5d 100644 --- a/src/Generic/List/OrderedList.hpp +++ b/src/Generic/List/OrderedList.hpp @@ -1,28 +1,47 @@ #ifndef HEADER_ORDEREDLIST #define HEADER_ORDEREDLIST +/*! \file OrderedList.hpp + * \brief Stores declaration and definition of templated class OrderedList + */ + #include "List.hpp" -template <class T> +/*! \brief Inherits List, but contains it's elements in a sorted manner + * + * \warning Outside those defined in List, insert() requires the type to have defined a "compare" of functions. + * \sa insert() + */ +template <typename T> class OrderedList : public List<T> { public: OrderedList(); OrderedList(const T* elements, unsigned elementsCount); + /*! \brief \warning Function is deleted, use insert() instead + * \sa insert() + */ void add(T element) = delete; + /*! \brief \warning Function is deleted, use insert() instead + * \sa insert() + */ void insertAt(T element, unsigned index) = delete; + //! Inserts an element at a sorted position void insert(T element); - // unsigned findIndex(const T& element) const; TODO: binary search }; -template <class T> +template <typename T> OrderedList<T>::OrderedList() : OrderedList(nullptr, 0) {} -template <class T> +template <typename T> OrderedList<T>::OrderedList(const T* elements, unsigned elementsCount) : List<T>::List(elements, elementsCount) {} -template <class T> +/*! + * \warning The function depends on the type having a function "compare" defined, which takes two elements and returns a number <0 if elem1 < elem2, >0 if elem1 > elem2, 0 if elem1 == elem2 + * \note Insertion is done linearly + */ +template <typename T> void OrderedList<T>::insert(T element) { if (List<T>::length == List<T>::count) List<T>::resize(); |
