using
System;
using
System.Collections.Generic;
class
MainClass {
public
static
void
QuickSort(List<
int
> arr,
int
low,
int
high) {
if
(low < high) {
int
pivot = high;
int
i = low - 1;
for
(
int
j = low; j <= high - 1; j++) {
if
(arr[j] <= arr[pivot]) {
i++;
arr.Swap(i, j);
}
}
arr.Swap(i + 1, pivot);
int
p = i + 1;
QuickSort(arr, low, p - 1);
QuickSort(arr, p + 1, high);
}
}
static
void
Main(
string
[] args) {
List<
int
> arr =
new
List<
int
>(
new
int
[] {5, 4, 3, 2, 1});
QuickSort(arr, 0, arr.Count - 1);
for
(
int
i = 0; i < arr.Count; i++) {
Console.Write(arr[i] +
" "
);
}
}
}
public
static
class
ListExtensions {
public
static
void
Swap<T>(
this
List<T> list,
int
index1,
int
index2) {
T temp = list[index1];
list[index1] = list[index2];
list[index2] = temp;
}
}