package com.sorts;
public class Sorts {
public static void main(String[] args) {
int a[] = {3,5,2,4,1,8,9};
// bubble(a);
// insert(a);
quick(a,0,a.length - 1);
for(int v : a) {
System.out.println(v);
}
}
public static void bubble(int a[]) {
for (int i = 0; i < a.length; i++) {
for (int j = i + 1; j < a.length; j++) {
if (a[i] > a[j]) {
int temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
}
public static void insert(int a[]) {
for (int i = 1; i < a.length; i++) {
int temp = a[i];
for (int j = i - 1;j >=0; j--) {
if (a[j] > temp) {
a[j+1] = a[j];
a[j] = temp;
}
// else {
// break;
// }
}
}
}
public static void quick(int a[],int l,int r) {
int i = l,j = r,x = a[l];
if (i < j) {
while (i < j) {
while(i < j && x < a[j])
j--;
if (i < j)
a[i++] = a[j];
while (i < j && x > a[i])
i++;
if (i < j)
a[j--] = a[i];
}
a[i] = x;
quick(a,l,i-1);
quick(a,i+1,r);
}
}
}