Macaulay2 Engine
Loading...
Searching...
No Matches

◆ sort2()

template<typename Sorter>
void QuickSorter< Sorter >::sort2 ( long lo,
long hi )
private

Definition at line 130 of file monsort.hpp.

131{
132 value pivot;
133 value t; /* temporary variable for swap */
134 if (end > begin)
135 {
136 long l = begin + 1;
137 long r = end;
140 t); /*** choose arbitrary pivot ***/
141 pivot = elems[begin];
142 while (l < r)
143 {
144 if (M->compare(elems[l], pivot) <= 0)
145 {
146 l++;
147 }
148 else
149 {
150 while (l < --r &&
151 M->compare(elems[r], pivot) >=
152 0) /*** skip superfluous swaps ***/
153 ;
154 swap(elems[l], elems[r], t);
155 }
156 }
157 l--;
158 swap(elems[begin], elems[l], t);
159 sort2(begin, l);
160 sort2(r, end);
161 }
162}
Sorter * M
Definition monsort.hpp:50
value * elems
Definition monsort.hpp:51
Sorter::value value
Definition monsort.hpp:49
void sort2(long lo, long hi)
Definition monsort.hpp:130
#define swap(a, b, t)
Definition monsort.hpp:127
#define pivot_index()
Definition monsort.hpp:126

References begin(), elems, end(), M, pivot_index, sort2(), and swap.

Referenced by sort(), and sort2().