ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
StrandSort.h

The strand sort, beyond the book, on a list with pointers. More...

Files

file  ADS/sort/StrandSort.h
 The strand sort, beyond the book, on a list with pointers [see List.h]: a strand, i.e., the first item and every later one not smaller than the last taken, is pulled out of the list and merged with the result, until the list is empty.

Functions

template<class T, class C = std::less<>>
void ADS::strandSort (List< T > &L, C less=C(), std::size_t *strands=nullptr)
 the strand sort of a list; the number of strands goes to *strands, if given

Detailed description

The strand sort, beyond the book, on a list with pointers.

The definitions, the invariants and the costs of the area are in Theory of sorting.

Function documentation

◆ strandSort()

template<class T, class C = std::less<>>
void ADS::strandSort ( List< T > & L,
C less = C(),
std::size_t * strands = nullptr )

the strand sort of a list; the number of strands goes to *strands, if given

In pseudocode (the natural merging of Knuth, section 5.2.4, beyond the book):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{strandSort}( L ) \cr 2 & \quad R \gets \text{an empty list} \cr 3 & \quad \textbf{while}\ L \text{ is not empty}\ \textbf{do} \cr 4 & \qquad S \gets ( \text{the head of } L \text{, removed from } L ) \cr 5 & \qquad \textbf{foreach}\ x \in L \text{ from its head}\ \textbf{do} \cr 6 & \qquad\quad \textbf{if}\ x \ge \text{the last item of } S \ \textbf{then}\ \text{move } x \text{ to the end of } S \cr 7 & \qquad R \gets \text{the merge of } R \text{ and } S \text{, } R \text{ first on a tie} \cr 8 & \quad L \gets R \end{array}} \]

Postcondition
\( L \) is sorted (audit)