package com.unit2.quicksort;
import java.util.Scanner;
public class Quick {
private static void quicksort(Comparable[] arr) {
sort(arr, 0, arr.length - 1);
}
private static void sort(Comparable[] arr, int lo, int hi) {
if (lo >= hi) {
return;
}
int lt = lo, i = lo + 1, gt = hi;
Comparable v = arr[lo];
while (i <= gt) {
int cmp = arr[i].compareTo(v);
if (cmp < 0) {
exch(arr, lt++, i++);
} else if (cmp > 0) {
exch(arr, i, gt--);
} else {
i++;
}
}
sort(arr, lo, lt - 1);
sort(arr, gt + 1, hi);
}
private static void exch(Comparable[] a, int i, int j) {
Comparable t = a[i];
a[i] = a[j];
a[j] = t;
}
private static void show(Comparable[] arr) {
for (Comparable i : arr) {
System.out.print(i + " ");
}
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
Comparable[] arr = new Comparable[10];
for (int i = 0; i < arr.length; i++) {
arr[i] = in.nextInt();
}
quicksort(arr);
show(arr);
}
}