Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- using namespace std;
- int quickSort(int Vet[], int inicio, int fim);
- int main(int argc, char** argv)
- {
- int n = 5;
- int vetor[] = {20, 35, 15, 12, 25};
- int i;
- quickSort (vetor, 0, 4);
- //no quick sort se passa o vetor o inicio do vetor e o fim e não o tamanho como os outros//
- printf("Vetor Ordenado Quick Sort\n\n");
- for(i = 0; i < n; i++)
- {
- printf (" %d ", vetor[i]);
- }
- printf ("\n");
- return 0;
- }
- int quickSort(int Vet[], int inicio, int fim)
- {
- int i, j, pivot, aux;
- i = inicio;
- j = fim;
- pivot = Vet[(inicio + fim) / 2];
- do
- {
- while (Vet[i] < pivot && i < fim) i++;
- while (pivot < Vet[j] && j > inicio) j--;
- if (i <= j)
- {
- if (i < j)
- {
- aux = Vet[i];
- Vet[i] = Vet[j];
- Vet[j] = aux ;
- }
- i++;
- j--;
- }
- }
- while (i <= j);
- if(inicio < j) quickSort (Vet, inicio, j);
- if(i < fim ) quickSort (Vet, i, fim);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement