MCPcopy Create free account
hub / github.com/chronoxor/CppBenchmark / QuickSortInternal

Method QuickSortInternal

examples/sort.cpp:326–360  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

324
325private:
326 static void QuickSortInternal(std::vector<int>& subitems, size_t left, size_t right)
327 {
328 // Choose the pivot item
329 int pivot = subitems[left + ((right - left) / 2) - 1];
330
331 size_t l = left;
332 size_t r = right;
333
334 while (l <= r)
335 {
336 // Move left if item is less than pivot
337 while ((l < right) && (subitems[l - 1] < pivot))
338 l++;
339 // Move right if item is less than pivot
340 while ((r > left) && (subitems[r - 1] > pivot))
341 r--;
342
343 if (l <= r)
344 {
345 // Swap left and right items
346 std::swap(subitems[l - 1], subitems[r - 1]);
347
348 // Move left and right indexes
349 ++l;
350 --r;
351 }
352 }
353
354 // Perform quick sort operation for the left sub items
355 if (left < r)
356 QuickSortInternal(subitems, left, r);
357 // Perform quick sort operation for the right sub items
358 if (l < right)
359 QuickSortInternal(subitems, l, right);
360 }
361};
362
363class QuickSort3 : public CppBenchmark::Benchmark, public SortFixture

Callers

nothing calls this directly

Calls 1

swapFunction · 0.50

Tested by

no test coverage detected