|
ADS
Algorithms and Data Structures
|
Algorithms on a SEQUENCE [see ADT.h], beyond the book, through its positions only, so that they work on a List and on an ArraySequence: More...
#include "ADS/ADT.h"#include "ADS/Contract.h"#include "ADS/sort/Sorted.h"#include <cstddef>#include <utility>#include "ADS/sequence/impl/SequenceAlgorithms.tpp"Go to the source code of this file.
Namespaces | |
| namespace | ADS |
Enumerations | |
| enum class | ADS::Order { ADS::Order::EMPTY , ADS::Order::CONSTANT , ADS::Order::INCREASING , ADS::Order::DECREASING , ADS::Order::NONDECREASING , ADS::Order::NONINCREASING , ADS::Order::NONE } |
| the order of a sequence, the most specific that holds More... | |
Functions | |
| template<Sequence S> | |
| long | ADS::search (const S &s, const typename S::Item &v) |
| the place of \( v \) counted from 0, or \( -( n + 1 ) \) | |
| template<Sequence S> | |
| long | ADS::searchOrdered (const S &s, const typename S::Item &v) |
| the place of \( v \) in the sorted \( s \), or \( -c \), \( c \) the comparisons made, -1 on the empty \( s \), so that a miss is always negative | |
| template<Sequence S> | |
| std::pair< typename S::Pos, bool > | ADS::lowerBound (const S &s, const typename S::Item &v) |
| the position of the first item not smaller than \( v \) in the sorted \( s \), or \( \mathit{pos}_n \), and whether it is \( v \): insert() of \( v \) there keeps \( s \) sorted | |
| template<Sequence S> | |
| S | ADS::sublist (const S &s, typename S::Pos p, typename S::Pos q) |
| the sequence of the items of \( s \) from the position \( p \) to the position \( q \), both included, empty if \( p \) is \( \mathit{pos}_n \) | |
| template<Sequence S> | |
| Order | ADS::order (const S &s) |
| the order of \( s \), the most specific that holds | |
| template<Sequence S> | |
| void | ADS::bubbleSort (S &s) |
| the bubble sort: at most \( n \) passes of swaps of adjacent items out of order, stopped at the first pass without swaps | |
| template<Sequence S> | |
| S | ADS::mergeSorted (const S &a, const S &b) |
| the merge of the sorted \( a \) and \( b \), the repeated items kept, those of \( a \) first among equals | |
| template<Sequence S> | |
| void | ADS::naturalMergeSort (S &s, long *passes=nullptr) |
| the natural merge sort; the number of passes goes to *passes, if given | |
| template<Sequence S> | |
| void | ADS::removeDuplicates (S &s) |
| keeps the first copy of each item, in \( O( n^2 ) \) comparisons | |
Algorithms on a SEQUENCE [see ADT.h], beyond the book, through its positions only, so that they work on a List and on an ArraySequence:
The contracts [see Contract.h]: searchOrdered() and mergeSorted() need sorted sequences, and the sorts, the merge and removeDuplicates() ensure a sorted result, or one without repetitions, of the right length; all of them cost \( O( n ) \) or more, and are audits, whose comparisons a comparator that counts its calls can skip [see checkingContract()]. The algorithms are defined in SequenceAlgorithms.tpp.