Complete the code to initialize the low pointer for the Dutch National Flag algorithm.
int low = [1];The low pointer starts at index 0 to begin partitioning from the start of the array.
Complete the code to swap elements at indices i and low.
int temp = arr[[1]]; arr[[2]] = arr[low]; arr[low] = temp;
We swap the element at index i with the element at index low to move smaller elements to the front.
Fix the error in the loop condition to correctly iterate over the array.
while (i [1] high) {
The loop should run while i <= high to properly handle the case when i equals high.
Fill both blanks to correctly update pointers after swapping with high.
int temp = arr[[1]]; arr[[2]] = arr[high]; arr[high] = temp; high--;
Swap element at i with element at high, then decrease high pointer.
Fill all three blanks to complete the Dutch National Flag partition loop.
while (i [1] high) { if (arr[i] [2] pivot) { int temp = arr[i]; arr[i] = arr[low]; arr[low] = temp; low++; i++; } else if (arr[i] [3] pivot) { int temp = arr[i]; arr[i] = arr[high]; arr[high] = temp; high--; } else { i++; } }
The loop runs while i <= high. If arr[i] < pivot, swap with low and increment both. If arr[i] > pivot, swap with high and decrement high. Else, just increment i.
