preview

The Importance Of Barching

Satisfactory Essays

bool isSorted(long long test[], const int N) { for (int i = 0; i < N - 1; i++) { if (test[i] > test[i + 1]) { return false; } } return true;
}

void merge(long long sort[], const int N, int low, int middle, int high) { long long sorted[N]; if (sort[middle] <= sort[middle + 1]) { //The right-most element of the left-half array is greater than or equal to the left-most element of the right half. return; } for (int c = 0; c <= high; c++) { sorted[c] = sort[c]; } for (int i = low, j = middle + 1, k = low; k <= high; k++) { if (i > middle) { sort[k] = sorted[j]; j++; } else if (j > high) { sort[k] = sorted[i]; i++; } else if (sorted[i] > sorted[j]) { sort[k] = sorted[j]; j++; } else { …show more content…

, const int N, int low, int high) { int i = low + 1, j = high, pivot = low; for (;;) { while (part[i] < part[pivot]) { if (i == high) { break; } ++i; } while (part[j] > part[pivot]) { if (j == low) { break; } --j; } if (i >= j) { break; } long long oldLeft = part[i]; part[i] = part[j]; part[j] = oldLeft; } long long oldLeft = part[pivot]; part[pivot] = part[j]; part[j] = oldLeft; return j;
}

void sink(int i, long long s[], const int N) { for (int j = i + i; i + i <= N; i = j) { if (j < N && j < j + 1) { j++; } else if (i >= j) { break; } long long oldLeft = s[i]; s[i] = s[j]; s[j] = oldLeft; }
}

void siftDown(long long sd[], int i, const int N) { while (i + i + 1 < N) { return; // TODO }
}

void insertionSort(long long insertion[], const int N) { for (long i = 0; i < N; i++) { for (long j = i; j > 0; j--) { if (insertion[j] < insertion[j - 1]) { long long oldLeft = insertion[j - 1]; insertion[j - 1] = insertion[j]; insertion[j] = oldLeft; } else { break; } } }
}

void shellSort(long long shell[], const int N, bool hType) { if (hType) { // A003462 int startH; for (startH = 0; startH < N / 2; startH = startH * 3 + 1); for (int h = startH; h > 0; h /= 3) { for (long i = h; i < N; i++) { for (long j = i; j >= h; j -= h) { if (shell[j] < shell[j - h]) { long long oldLeft = shell[j - h]; shell[j - h] = shell[j]; shell[j] =

Get Access