Pagini recente » Cod sursa (job #255844) | Cod sursa (job #2642776) | Cod sursa (job #1956593) | Cod sursa (job #2246557) | Cod sursa (job #2192603)
import java.io.IOException;
import java.io.PrintStream;
import java.io.FileInputStream;
import java.util.Scanner;
public class Main {
public static void main(String [] args) throws IOException {
Scanner sc = new Scanner(new FileInputStream("algsort.in"));
PrintStream out = new PrintStream("algsort.out");
int [] v = new int[500000];
int n, i;
n = sc.nextInt();
for(i = 0; i < n; i++)
v[i] = sc.nextInt();
quickSort(0,n-1,v);
for(i = 0; i < n; i++)
out.print(v[i] + " ");
out.print("\n");
sc.close();
out.close();
}
public static void quickSort(int Begin, int End, int [] v) {
int b = Begin, e = End, pivot = v[(b+e)/2];
int aux;
while(b <= e) {
while(v[b] < pivot) b++;
while(v[e] > pivot) e--;
if(b <= e) {
aux = v[b];
v[b] = v[e];
v[e] = aux;
b++;
e--;
}
}
if(Begin < e) quickSort(Begin,e,v);
if(b < End) quickSort(b,End,v);
}
}