Website Summary Files Commits Branches @commit @diff @stats
path: root / src / Generic / List / OrderedList.hpp
diff options
context:
space:
mode:
Commitb844597fd23bc57aa97e231fc90eecfd6322cecc (patch)
Author
 Syndamia <kamen.d.mladenov@protonmail.com>
2022-05-07 08:28:27 +0300
Committer
 Syndamia <kamen.d.mladenov@protonmail.com>
2022-05-07 08:28:27 +0300
Files86a4112ecfa1e3a54dbcf44a7ddf37575ba4aa39 /src/Generic/List/OrderedList.hpp
FMI-OOP-P1_TicketSystem-b844597fd23bc57aa97e231fc90eecfd6322cecc.tar
FMI-OOP-P1_TicketSystem-b844597fd23bc57aa97e231fc90eecfd6322cecc.tar.gz
FMI-OOP-P1_TicketSystem-b844597fd23bc57aa97e231fc90eecfd6322cecc.zip
Parent0910afb91c8f9672be1d6184f47fb75947ea14f1 (diff)
Reorganized whole architecture
1 files changed, 36 insertions, 0 deletions
-rw-r--r--src/Generic/List/OrderedList.hpp36
diff --git a/src/Generic/List/OrderedList.hpp b/src/Generic/List/OrderedList.hpp
new file mode 100644
index 0000000..4396d33
--- /dev/null
+++ b/src/Generic/List/OrderedList.hpp
@@ -0,0 +1,36 @@
+#ifndef HEADER_ORDEREDLIST
+#define HEADER_ORDEREDLIST
+
+#include "List.hpp"
+
+template <class T>
+class OrderedList : public List<T> {
+public:
+ OrderedList();
+ OrderedList(const T* elements, unsigned elementsCount);
+
+ void add(const T& element) = delete;
+ void insertAt(const T& element, unsigned index) = delete;
+
+ void insert(const T& element);
+ // unsigned findIndex(const T& element) const; TODO: binary search
+};
+
+template <class T>
+OrderedList<T>::OrderedList() : OrderedList(nullptr, 0) {}
+
+template <class T>
+OrderedList<T>::OrderedList(const T* elements, unsigned elementsCount) : List<T>::List(elements, elementsCount) {}
+
+template <class T>
+void OrderedList<T>::insert(const T& element) {
+ if (List<T>::length == List<T>::count) List<T>::resize();
+
+ unsigned insertionInd = 0;
+ while (List<T>::elements[insertionInd].compare(element) < 0 && insertionInd < List<T>::count)
+ insertionInd++;
+
+ List<T>::insertAt(element, insertionInd);
+}
+
+#endif