| 155 | } |
| 156 | } |
| 157 | static void MyQuickSortAscending(Real* first, Real* last, int depth) |
| 158 | { |
| 159 | REPORT |
| 160 | for (;;) |
| 161 | { |
| 162 | const int length = last - first + 1; |
| 163 | if (length < DoSimpleSort) { REPORT return; } |
| 164 | if (depth++ > MaxDepth) |
| 165 | Throw(ConvergenceException("QuickSortAscending fails: ")); |
| 166 | Real* centre = first + length/2; |
| 167 | const Real test = SortThreeDescending(last, centre, first); |
| 168 | Real* f = first; Real* l = last; |
| 169 | for (;;) |
| 170 | { |
| 171 | while (*(++f) < test) {} |
| 172 | while (*(--l) > test) {} |
| 173 | if (l <= f) break; |
| 174 | const Real temp = *f; *f = *l; *l = temp; |
| 175 | } |
| 176 | if (f > centre) |
| 177 | { REPORT MyQuickSortAscending(l+1, last, depth); last = f-1; } |
| 178 | else { REPORT MyQuickSortAscending(first, f-1, depth); first = l+1; } |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | //********* sort diagonal matrix & rearrange matrix columns **************** |
| 183 |
no test coverage detected