2#ifndef SORTEDARRAY_H_INCLUDED
3#define SORTEDARRAY_H_INCLUDED
33 template <
typename... Args>
35 this->
init(arg1, args...);
49 virtual int add(
const T &
object)
override;
65 virtual int find(
const T &
object)
const override;
79 virtual int findInsert(
const T &
object,
bool allowDuplicates =
true)
const;
82 virtual void shuffle() noexcept
override {}
85 virtual void reverse() noexcept
override {}
92 this->
insert(
object, index);
106 while (left < right) {
107 int center = (left + right) / 2;
111 }
else if (this->
gt(this->
array_data.at(center),
object)) {
134 while (left < right) {
135 int center = (left + right) / 2;
139 }
else if (this->
gt(this->
array_data.at(center),
object)) {
142 return allowDuplicates ? center : -1;
148 }
else if (allowDuplicates || !this->
eq(this->
array_data.at(left),
object)) {
virtual bool eq(const T &arg1, const T &arg2) const
Check if two objects are equal.
Definition array.hpp:74
void init(const T &arg1)
Helper function for single object initialization.
Definition array.hpp:47
std::vector< T > array_data
The data in the array.
Definition array.hpp:41
array()
Default constructor.
Definition array.hpp:112
array & insert(const T &, int)
Insert an object into the array.
Definition array.hpp:999
virtual bool gt(const T &arg1, const T &arg2) const
Check if one object is greater than another.
Definition array.hpp:90
virtual bool lt(const T &arg1, const T &arg2) const
Check if one object is less than another.
Definition array.hpp:106
virtual void shuffle() noexcept override
Shuffle the elements of the array into a random order.
Definition sortedArray.hpp:82
sortedArray(const T &arg1, const Args &...args)
List-initialized constructor.
Definition sortedArray.hpp:34
virtual void reverse() noexcept override
Reverse the order of all elements in the array.
Definition sortedArray.hpp:85
virtual int find(const T &object) const override
Check if a given object is in the array.
Definition sortedArray.hpp:98
virtual int findInsert(const T &object, bool allowDuplicates=true) const
Find an index where the given object can be inserted while keeping the array sorted.
Definition sortedArray.hpp:126
sortedArray()
Default constructor.
Definition sortedArray.hpp:21
virtual int add(const T &object) override
Add an object to the array.
Definition sortedArray.hpp:89
Section containing core functions and classes.