How it works
Multiply and surrender.
Implementation
function slowSort(arr, stats) { function slow(i, j) { if (i >= j) return; const m = Math.floor((i + j) / 2); slow(i, m); slow(m + 1, j); compare(m, j); if (arr[j] < arr[m]) { [arr[j], arr[m]] = [arr[m], arr[j]]; swap(m, j); } slow(i, j - 1); } if (arr.length > 1) slow(0, arr.length - 1); }
def slowSort(arr, stats): def slow(i, j): if (i >= j): return m = ((i + j) // 2) slow(i, m) slow((m + 1), j) compare(m, j) if (arr[j] < arr[m]): arr[j], arr[m] = arr[m], arr[j] swap(m, j) slow(i, (j - 1)) if (len(arr) > 1): slow(0, (len(arr) - 1))
#include <vector> #include <algorithm> void slow(int i, int j); void slow(int i, int j) { if((i >= j)) { return; } int m = ((i + j) / 2); slow(i, m); slow((m + 1), j); compare(m, j); if((arr[j] < arr[m])) { std::swap(arr[j], arr[m]); swap(m, j); } slow(i, (j - 1)); } void sort(std::vector<int>& arr, int n, int& comparisons, int& swaps) { if((n > 1)) { slow(0, (n - 1)); } }
void slow(int i, int j) { if((i >= j)) { return; } int m = ((i + j) / 2); slow(i, m); slow((m + 1), j); compare(m, j); if((arr[j] < arr[m])) { { int _t = arr[j]; arr[j] = arr[m]; arr[m] = _t; } swap(m, j); } slow(i, (j - 1)); } public void Sort(int[] arr, int n, dynamic stats) { if((n > 1)) { slow(0, (n - 1)); } }
#include <stdio.h> void slow(int i, int j); void slow(int i, int j) { if((i >= j)) { return; } int m = ((i + j) / 2); slow(i, m); slow((m + 1), j); compare(m, j); if((arr[j] < arr[m])) { { int _t = arr[j]; arr[j] = arr[m]; arr[m] = _t; } swap(m, j); } slow(i, (j - 1)); } void sort(int arr[], int n, int* comparisons, int* swaps) { if((n > 1)) { slow(0, (n - 1)); } }