ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
SequenceAlgorithms.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*----------------------- File SequenceAlgorithms.h ------------------------*/
3/*--------------------------------------------------------------------------*/
47/*--------------------------------------------------------------------------*/
48/*----------------------------- DEFINITIONS --------------------------------*/
49/*--------------------------------------------------------------------------*/
50
51#ifndef __ADS_SequenceAlgorithms
52 #define __ADS_SequenceAlgorithms
53/* self-identification: #endif constant */
54
55/*--------------------------------------------------------------------------*/
56/*------------------------------ INCLUDES ----------------------------------*/
57/*--------------------------------------------------------------------------*/
58
59#include "ADS/ADT.h"
60#include "ADS/Contract.h"
61#include "ADS/sort/Sorted.h"
62
63#include <cstddef>
64#include <utility>
65
66/*--------------------------------------------------------------------------*/
67/*--------------------------- NAMESPACE ------------------------------------*/
68/*--------------------------------------------------------------------------*/
69
70namespace ADS
71{
72
73/*--------------------------------------------------------------------------*/
74/*------------------------------- SEARCH -----------------------------------*/
75/*--------------------------------------------------------------------------*/
76
93template< Sequence S >
94long search( const S & s , const typename S::Item & v );
95
117template< Sequence S >
118long searchOrdered( const S & s , const typename S::Item & v );
119
136template< Sequence S >
137std::pair< typename S::Pos , bool > lowerBound( const S & s ,
138 const typename S::Item & v );
139
160template< Sequence S >
161S sublist( const S & s , typename S::Pos p , typename S::Pos q );
162
163/*--------------------------------------------------------------------------*/
164/*------------------------------- ORDER ------------------------------------*/
165/*--------------------------------------------------------------------------*/
166
177
201template< Sequence S >
202Order order( const S & s );
203
204/*--------------------------------------------------------------------------*/
205/*------------------------------- SORTING ----------------------------------*/
206/*--------------------------------------------------------------------------*/
207
227template< Sequence S >
228void bubbleSort( S & s );
229
255template< Sequence S >
256S mergeSorted( const S & a , const S & b );
257
281template< Sequence S >
282void naturalMergeSort( S & s , long * passes = nullptr );
283
298template< Sequence S >
299void removeDuplicates( S & s );
300
301/*--------------------------------------------------------------------------*/
302
303} // end( namespace ADS )
304
305/*--------------------------------------------------------------------------*/
306/*-------------------------- IMPLEMENTATION --------------------------------*/
307/*--------------------------------------------------------------------------*/
308
309#include "ADS/sequence/impl/SequenceAlgorithms.tpp"
310
311/*--------------------------------------------------------------------------*/
312
313#endif /* SequenceAlgorithms.h included */
314
315/*--------------------------------------------------------------------------*/
316/*--------------------- End File SequenceAlgorithms.h ----------------------*/
317/*--------------------------------------------------------------------------*/
The abstract data types of the book, as concepts of C++20: SEQUENCE, SET and DICTIONARY (chapter 3),...
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The checks of the contracts of the sorts [see Contract.h]: a copy of the input kept only when the aud...
std::size_t lowerBound(const std::vector< T > &A, const T &v, std::size_t lo, std::size_t hi, C less=C())
the first place in of an item not smaller than , if none
Order order(const S &s)
the order of , the most specific that holds
Order
the order of a sequence, the most specific that holds
Definition SequenceAlgorithms.h:168
void bubbleSort(S &s)
the bubble sort: at most passes of swaps of adjacent items out of order, stopped at the first pass w...
void naturalMergeSort(S &s, long *passes=nullptr)
the natural merge sort; the number of passes goes to *passes, if given
long search(const S &s, const typename S::Item &v)
the place of counted from 0, or
S sublist(const S &s, typename S::Pos p, typename S::Pos q)
the sequence of the items of from the position to the position , both included, empty if is
S mergeSorted(const S &a, const S &b)
the merge of the sorted and , the repeated items kept, those of first among equals
void removeDuplicates(S &s)
keeps the first copy of each item, in comparisons
long searchOrdered(const S &s, const typename S::Item &v)
the place of in the sorted , or , the comparisons made, -1 on the empty , so that a miss is always ...
@ NONINCREASING
decreasing, with some equal items
Definition SequenceAlgorithms.h:174
@ CONSTANT
all the items equal
Definition SequenceAlgorithms.h:170
@ NONDECREASING
increasing, with some equal items
Definition SequenceAlgorithms.h:173
@ NONE
neither increasing nor decreasing
Definition SequenceAlgorithms.h:175
@ EMPTY
no item
Definition SequenceAlgorithms.h:169
@ DECREASING
each item smaller than the one before
Definition SequenceAlgorithms.h:172
@ INCREASING
each item larger than the one before
Definition SequenceAlgorithms.h:171
Definition ADT.h:96