Mid From PDF Coding C# Coding Interview

Quicksort?

void QuickSort(int[] arr, int low, int high)

{
if (low < high)

Follow on:

{
int pi = Partition(arr, low, high);

QuickSort(arr, low, pi - 1);

QuickSort(arr, pi + 1, high);

}
}
int Partition(int[] arr, int low, int high)
{
int pivot = arr[high];
int i = low - 1;
for (int j = low; j < high; j++)
{
if (arr[j] < pivot)
{

i++;

(arr[i], arr[j]) = (arr[j], arr[i]);
}
}
(arr[i + 1], arr[high]) = (arr[high], arr[i + 1]);
return i + 1;
}

Explanation:

Choose last element as pivot, partition array so left < pivot < right, recursively sort

subarrays.

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