Anonymous
public cpp v1 · immutable ////////////////////////// // M E R G E S O R T // ////////////////////////// void merge(int array[], int begin, int mid, int end) { int low_count = begin; int high_count = mid++; int *storage = new int[end]; int index = 0; while ( (low_count <= mid) && (high_count <= end) ) { if (array[low_count] <= array[high_count]) { storage[index] = array[low_count]; low_count++; } else { storage[index] = array[high_count]; high_count++; } index++; } while (low_count <= mid) storage[index++] = array[low_count++]; while (high_count <= end) storage[index++] = array[high_count++]; for (int r = begin ; r <= end ; r++) array[r] = storage[r/*-begin*/]; } void mergesort (int array[], int begin, int end) { if (begin == end) return; int mid = (begin + end) / 2; mergesort(array, begin, mid); mergesort(array, mid + 1, end); merge(array, begin, mid, end); }