Mid Coding

Sort Array of 0s, 1s, and 2s (Dutch National Flag)?

void SortColors(int[] nums)

int low = 0, mid = 0, high = nums.Length - 1;

while (mid <= high)

if (nums[mid] == 0)

(nums[low++], nums[mid++]) = (nums[mid], nums[low]);

else if (nums[mid] == 1)

mid++;

else

(nums[mid], nums[high--]) = (nums[high], nums[mid]);

Follow on:

Explanation:

Partition array into three parts in one pass using three pointers.

More from C# Programming Tutorial

All questions for this course