Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void selecao (int vetor[], int n);
- void linha ();
- int main(int argc, char** argv)
- {
- //int j;
- int n = 5;
- int vetor[5] = {20, 35, 15, 12, 25};
- cout << "Vetor Desordenado" << endl;
- for(int i = 0; i < n; i++)
- {
- cout << vetor[i] << " ";
- }
- cout << endl << endl;
- selecao (vetor, n);
- cout << "Ordenacao selection sort" << endl;
- for (int i = 0; i < n; i++)
- {
- cout << vetor[i] << " ";
- }
- cout << endl;
- return 0;
- }
- void selecao (int vetor[], int n)
- {
- int menor, aux;
- for(int i = 0; i < n - 1; i++)
- {
- menor = i;
- for(int j = i + 1; j < n; j++)
- {
- if(vetor[menor] > vetor[j])
- {
- cout << " testa " << vetor[menor] << " > " << vetor[j] << " True" << endl;
- cout << " Troca " << vetor[menor] << " e " << vetor[j] << endl;
- for(int i = 0; i < n; i++)
- {
- cout << " " << vetor[i];
- }
- menor = j;
- cout << endl;
- cout << endl;
- linha ();
- }
- else if(vetor[menor] < vetor[j])
- {
- cout << " testa " << vetor[menor] << " > " << vetor[j] << " False" << endl;
- }
- }
- if (i != menor)
- {
- aux = vetor[i];
- vetor[i] = vetor[menor];
- vetor[menor] = aux;
- }
- }
- }
- void linha ()
- {
- cout << "--------------------------------------------" << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement