Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void quicksort(int vect[]) {
- int[] vetor = vect;
- quickSort(vetor, 0, vetor.length - 1);
- }
- private static void quickSort(int[] vetor, int inicio, int fim) {
- if (inicio < fim) {
- int posicaoPivo = separar(vetor, inicio, fim);
- quickSort(vetor, inicio, posicaoPivo - 1);
- quickSort(vetor, posicaoPivo + 1, fim);
- }
- }
- private static int separar(int[] vetor, int inicio, int fim) {
- int pivo = vetor[inicio];
- int i = inicio + 1, f = fim;
- while (i <= f) {
- if (vetor[i] <= pivo)
- i++;
- else if (pivo < vetor[f])
- f--;
- else {
- int troca = vetor[i];
- vetor[i] = vetor[f];
- vetor[f] = troca;
- i++;
- f--;
- }
- }
- vetor[inicio] = vetor[f];
- vetor[f] = pivo;
- return f;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement