Mid From PDF Coding C# Coding Interview

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
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details