package sort;
public class Quicksort {
public static void main(String[] args) {
int[] s = { 13, 15, 7, 10, 20, 4, 8, 19 };
// s = quicksort(s, 0, s.length - 1);
s = quicks(s, 0, s.length - 1);
for (int i : s) {
System.out.print(i + " ");
}
}
public static int[] quickd(int[] num, int left, int right) {
if (left < right) {
int k = doublequick(num, left, right);
System.out.println("k=" + k);
quickd(num, left, k - 1);
quickd(num, k + 1, right);
}
return num;
}
public static int[] quicks(int[] num, int left, int right) {
if (left < right) {
int k = singlequick(num, left, right);
System.out.println("k=" + k);
quicks(num, left, k - 1);
quicks(num, k + 1, right);
}
return num;
}
public static int doublequick(int[] s, int left, int right) {
int i = left;
int j = right;
int temp;
int x = s[i];
while (i < j) {
while (i < j && s[j] >= x)
j--;
temp = s[j];
s[j] = s[i];
s[i] = temp;
while (i < j && s[i] <= x)
i++;
temp = s[j];
s[j] = s[i];
s[i] = temp;
}
return i;
}
public static int singlequick(int[] s, int left, int right) {
int i = left;
int j = right;
int x = s[left];
while (i < j) {
while (i < j && s[j] >= x)
j--;
s[i] = s[j];
while (i < j && s[i] <= x)
i++;
s[j] = s[i];
}
s[i] = x;
System.out.println("i=" + i);
return i;
}
public static int[] quicksort(int[] s, int left, int right) {
int i = left;
int j = right;
int middle = s[(i + j) / 2];
System.out.println(middle);
do {
while (i <= right && middle > s[i])
i++;
while (j >= left && middle < s[j])
j--;
if (i <= j) {
int temp = s[j];
s[j] = s[i];
s[i] = temp;
i++;
j--;
}
} while (i <= j);
for (int k : s) {
System.out.print(k + " ");
}
if (left < j) {
System.out.println("j=" + j);
quicksort(s, left, j);
}
if (right > i) {
System.out.println("i=" + i);
quicksort(s, i, right);
}
return s;
}
}
public class Quicksort {
public static void main(String[] args) {
int[] s = { 13, 15, 7, 10, 20, 4, 8, 19 };
// s = quicksort(s, 0, s.length - 1);
s = quicks(s, 0, s.length - 1);
for (int i : s) {
System.out.print(i + " ");
}
}
public static int[] quickd(int[] num, int left, int right) {
if (left < right) {
int k = doublequick(num, left, right);
System.out.println("k=" + k);
quickd(num, left, k - 1);
quickd(num, k + 1, right);
}
return num;
}
public static int[] quicks(int[] num, int left, int right) {
if (left < right) {
int k = singlequick(num, left, right);
System.out.println("k=" + k);
quicks(num, left, k - 1);
quicks(num, k + 1, right);
}
return num;
}
public static int doublequick(int[] s, int left, int right) {
int i = left;
int j = right;
int temp;
int x = s[i];
while (i < j) {
while (i < j && s[j] >= x)
j--;
temp = s[j];
s[j] = s[i];
s[i] = temp;
while (i < j && s[i] <= x)
i++;
temp = s[j];
s[j] = s[i];
s[i] = temp;
}
return i;
}
public static int singlequick(int[] s, int left, int right) {
int i = left;
int j = right;
int x = s[left];
while (i < j) {
while (i < j && s[j] >= x)
j--;
s[i] = s[j];
while (i < j && s[i] <= x)
i++;
s[j] = s[i];
}
s[i] = x;
System.out.println("i=" + i);
return i;
}
public static int[] quicksort(int[] s, int left, int right) {
int i = left;
int j = right;
int middle = s[(i + j) / 2];
System.out.println(middle);
do {
while (i <= right && middle > s[i])
i++;
while (j >= left && middle < s[j])
j--;
if (i <= j) {
int temp = s[j];
s[j] = s[i];
s[i] = temp;
i++;
j--;
}
} while (i <= j);
for (int k : s) {
System.out.print(k + " ");
}
if (left < j) {
System.out.println("j=" + j);
quicksort(s, left, j);
}
if (right > i) {
System.out.println("i=" + i);
quicksort(s, i, right);
}
return s;
}
}