Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- void InsertionSort (int array[], int tam);
- void linha ();
- int main(int argc, char** argv)
- {
- int n = 5;
- int vetor[] = {20, 35, 15, 12, 25};
- cout << "\t Vetor" << endl << endl;
- for(int i = 0; i < n; i++)
- {
- cout << " " << vetor[i] << " ";
- }
- cout << endl << endl;;
- InsertionSort (vetor, n);
- cout << "Ordenacao Insertion Sort" << endl << endl;
- for(int i = 0; i < n; i++)
- {
- cout << vetor[i] << " ";
- }
- cout << endl;
- return 0;
- }
- void InsertionSort (int array[], int tam)
- {
- int j, temp;
- for(int i = 1; i < tam; i++)
- {
- j = i;
- while(j > 0 && array[j - 1] > array[j])
- {
- cout << " testa " << array[j - 1] << " > " << array[j] << " True" << endl;
- cout << " Troca " << array[j - 1] << " e " << array[j] << endl;
- temp = array[j];
- array[j] = array[j - 1];
- array[j - 1] = temp;
- for(int i = 0; i < tam; i++)
- {
- cout << " " << array[i];
- }
- cout << endl;
- cout << endl;
- linha ();
- j--;
- }
- }
- }
- void linha ()
- {
- cout << "--------------------------------------------" << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment