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] =
2, 2, 0, 5,1, 4,1, 3, 0, 0, 1, 4, 4, 0,1, 4, 3, 4, 2, 1
|1 |$ 60 |$ 45 |$ 105 |$ 60 |$ 45 |$ 105 |$ 45 |
Create 2 formulas, one that will calculate the last number in terms of the first number and a constant increase in rate as well as the total amount of numbers. The second formula will add ass of the resulting numbers from the first formula together after the last number is calculated.
addi $sp, $sp, 4 # pop 1 element from the stack and the space is reused for $s0
5.For 5 disks, it will take 31 moves: 2n + 1 = 215 + 1 =31
for (int j=i+1; j < n; j++)// defines j as one larger than i, compares j to n, increments j each iteration
Loop While ans <> "Y" And ans <> "y" And ans <> "N" And ans <> "n"
Minimum element was initially zero, which resulted in a wrong output. Using the debugger to check how For-Loop iterated, I found the initial problem of min = 0 that caused IF statement to be always False. Thus, I changed min=0; to min=num[0] and the program begun to work perfect.
2, 2, 0, 5,1, 4,1, 3, 0, 0, 1, 4, 4, 0,1, 4, 3, 4, 2, 1
G, L, H, D, B, M, N, I, E, O, J, P, K, F, C, A
For this assignment I develop and either pseudo code or a flowchart for my following programming problem.
To determine if an integer in [a, b] evenly divides c I would iterate from a to
3 4 167 0.075 1,060 0.48 204 241 — 340 213 1.0 0.3 59.2 10.7 0.20 63.5 1,124 521 22.5 3,293 98,100 624 16 22 5 19 — 974 944 11,511 48
6 95 111 135 155 160 114 55 33 41 92 91 91 61 67 118 136 131 94 26 11 8