Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- const int tam = 10;
- typedef int tvet[tam];
- void QuickSort(tvet &vet, int inicio, int fim)
- {
- int i = inicio, j = fim;
- int aux;
- int pivot = vet[(inicio + fim) / 2];
- while (i <= j)
- {
- while (vet[i] < pivot)
- i++;
- while (vet[j] > pivot)
- j--;
- if (i <= j)
- {
- aux = vet[i];
- vet[i] = vet[j];
- vet[j] = aux;
- i++;
- j--;
- }
- }
- if (inicio < j)
- QuickSort(vet, inicio, j);
- if (i < fim)
- QuickSort(vet, i, fim);
- }
- void ExibeVetor(tvet vet)
- {
- for(int i = 0; i < tam; i++)
- cout << vet[i] << " ";
- }
- int main()
- {
- tvet Vetor;
- int i;
- srand(time(NULL));
- for(i = 0; i < tam; i++)
- {
- Vetor[i+1] = Vetor[i];
- Vetor[i] = rand()%50;
- }
- cout << "Os valores do vetor sao:" << endl;
- for(i = 0; i < tam; i++)
- cout << Vetor[i] << " ";
- QuickSort(Vetor, 0, tam - 1);
- cout << "\nOs valores do vetor ordenado sao:" << endl;
- ExibeVetor(Vetor);
- system("PAUSE");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement