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

◆ sort2depth()

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

Definition at line 169 of file monsort.hpp.

170{
171 value pivot;
172 value t; /* temporary variable for swap */
173 if (depth > maxdepth) maxdepth = depth;
174 if (end > begin)
175 {
176 long l = begin + 1;
177 long r = end;
180 t); /*** choose arbitrary pivot ***/
181 pivot = elems[begin];
182 while (l < r)
183 {
184 if (M->compare(elems[l], pivot) <= 0)
185 {
186 l++;
187 }
188 else
189 {
190 while (l < --r &&
191 M->compare(elems[r], pivot) >=
192 0) /*** skip superfluous swaps ***/
193 ;
194 swap(elems[l], elems[r], t);
195 }
196 }
197 l--;
198 swap(elems[begin], elems[l], t);
199 sort2depth(begin, l, depth + 1);
200 sort2depth(r, end, depth + 1);
201 }
202}
Sorter * M
Definition monsort.hpp:50
value * elems
Definition monsort.hpp:51
void sort2depth(long lo, long hi, long depth)
Definition monsort.hpp:169
Sorter::value value
Definition monsort.hpp:49
long maxdepth
Definition monsort.hpp:53
#define swap(a, b, t)
Definition monsort.hpp:127
#define pivot_index()
Definition monsort.hpp:126

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

Referenced by sort(), and sort2depth().