using System.Collections.Generic;
using System.Threading.Tasks;
namespace Algorithms.Sorting
public class QuickSortInPlace : ISort
public void Sort(IComparable[] a) {
for (int i = h; i < N; i++)
for (int j = i; j >= h; j=j-h)
if (Less(a[j], a[j - h]))
private void Sort(IComparable[] a, int lo, int hight) {
int j = Partition(a, lo, hight);
private int Partition(IComparable[] a, int lo, int hight) {
if (i ==hight) { break; }
public bool Less(IComparable v, IComparable w) {
return v.CompareTo(w) < 0;
public void Exchange(IComparable[] a, int i, int j) {
public void Show(IComparable[] a) {
Console.WriteLine("***********************************");
Console.WriteLine($"QuickSortInPlace tests");
Console.WriteLine("***********************************");
var sorted = IsSorted(a);
Console.WriteLine($"IsSorted is {sorted}");
for (int i = 0; i < a.Length; i++)
Console.Write(a[i] + " ");
public bool IsSorted(IComparable[] a) {
for (int i = 1; i < a.Length; i++)
if (Less(a[i], a[i - 1]))
public static void RunTest() {
var s = new QuickSortInPlace();
IComparable[] c = new IComparable[a.Length];
for (int i = 0; i < a.Length; i++)
c[i] = (IComparable) a[i];