Sorted Vector
|
 |
A dynamic array that
automatically sorts and adjusts itself.
This is an array, with the
advantage of adjusting its own length for efficiency, with fast logarithmic
access time (binary search).
Declaration
#include<ospace/advanced/sortvctr.h>
template
<
class Instantiator
>
class os_Sorted_Vector
Interface
Constructor
os_Sorted_Vector(int init = 32, int incr
= 32, Sort_Order odr = ASCENDING)
This the default
constructor. init is the initial size of array, and incr is the size by
which array will grow or shrink as needed. Sort order is ascending by
default, can also be set to DESCENDING.
Destructor
~os_Sorted_Vector()
Destroys all entries in
the vector.
insert
void insert(const T&
item)
Adds a new element to the
vector. Sorts itself automatically, and grows as needed.
add
void
add(T item)
This is same as insert,
except pass is by value, mainly for string literals like "abc".
remove
int remove(const T&
item)
Removes item and shrinks
as needed.
removeAt
void
removeAt(int index)
Removes the element at
index, and shrinks as needed.
modify
void
modify(int index, const T& item)
The item at index is set
to item. Vector remains sorted.
find
int find(const T&
item)
Returns the index of item
in vector.
operator[]
const T&
operator[](int index)
Returns a const reference
to item at index.
number
int
number(void)
Returns the number of
elements in the vector.
Copyright©2005-2026 Recursion Software LLC
All Rights Reserved - For use by licensed users only.