Website Summary Files Commits Branches @commit @diff @stats
path: root / src / List / OrderedList.hpp
diff options
context:
space:
mode:
Commitb0f046461b44a0c4002ea667a726403ff4a1a701 (patch)
Author
 Syndamia <kamen.d.mladenov@protonmail.com>
2022-05-04 10:58:48 +0300
Committer
 Syndamia <kamen.d.mladenov@protonmail.com>
2022-05-04 10:58:48 +0300
Filesd5a340a133f2f18394445446b218e56765ecb4a5 /src/List/OrderedList.hpp
FMI-OOP-P1_TicketSystem-b0f046461b44a0c4002ea667a726403ff4a1a701.tar
FMI-OOP-P1_TicketSystem-b0f046461b44a0c4002ea667a726403ff4a1a701.tar.gz
FMI-OOP-P1_TicketSystem-b0f046461b44a0c4002ea667a726403ff4a1a701.zip
Parentbff99a11272743fb1caa4b7d345ebb3b0f8a5609 (diff)
Moved templated stuff into hpp files and added a blank main.cpp file
1 files changed, 36 insertions, 0 deletions
-rw-r--r--src/List/OrderedList.hpp36
diff --git a/src/List/OrderedList.hpp b/src/List/OrderedList.hpp
new file mode 100644
index 0000000..4396d33
--- /dev/null
+++ b/src/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