From 4f27fe893c0e5b85122a228dd66f79bc8fa87088 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Mon, 2 May 2022 22:01:24 +0300 Subject: Fixed OrderedList location --- List/OrderedList.cpp | 12 ------------ List/OrderedList.h | 16 ---------------- src/List/OrderedList.cpp | 12 ++++++++++++ src/List/OrderedList.h | 16 ++++++++++++++++ 4 files changed, 28 insertions(+), 28 deletions(-) delete mode 100644 List/OrderedList.cpp delete mode 100644 List/OrderedList.h create mode 100644 src/List/OrderedList.cpp create mode 100644 src/List/OrderedList.h diff --git a/List/OrderedList.cpp b/List/OrderedList.cpp deleted file mode 100644 index f3a7450..0000000 --- a/List/OrderedList.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "OrderedList.h" - -template -bool OrderedList::insert(const T& element) { - if (List::length == List::count) List::resize(); - - unsigned insertionInd = 0; - while (List::elements[insertionInd].compare(element) < 0 && insertionInd < List::count) - insertionInd++; - - return List::insertAt(element, insertionInd); -} diff --git a/List/OrderedList.h b/List/OrderedList.h deleted file mode 100644 index 22f05df..0000000 --- a/List/OrderedList.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef HEADER_ORDEREDLIST -#define HEADER_ORDEREDLIST - -#include "List.h" - -template -class OrderedList : public List { -public: - void add(const T& element) = delete; - bool insertAt(const T& element, unsigned index) = delete; - - bool insert(const T& element); - // unsigned findIndex(const T& element) const; TODO: binary search -}; - -#endif diff --git a/src/List/OrderedList.cpp b/src/List/OrderedList.cpp new file mode 100644 index 0000000..f3a7450 --- /dev/null +++ b/src/List/OrderedList.cpp @@ -0,0 +1,12 @@ +#include "OrderedList.h" + +template +bool OrderedList::insert(const T& element) { + if (List::length == List::count) List::resize(); + + unsigned insertionInd = 0; + while (List::elements[insertionInd].compare(element) < 0 && insertionInd < List::count) + insertionInd++; + + return List::insertAt(element, insertionInd); +} diff --git a/src/List/OrderedList.h b/src/List/OrderedList.h new file mode 100644 index 0000000..22f05df --- /dev/null +++ b/src/List/OrderedList.h @@ -0,0 +1,16 @@ +#ifndef HEADER_ORDEREDLIST +#define HEADER_ORDEREDLIST + +#include "List.h" + +template +class OrderedList : public List { +public: + void add(const T& element) = delete; + bool insertAt(const T& element, unsigned index) = delete; + + bool insert(const T& element); + // unsigned findIndex(const T& element) const; TODO: binary search +}; + +#endif -- cgit v1.3.1-26-gb76a