Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <array>
- using namespace std;
- void swap (int& a, int& b)
- {
- int aux = a;
- a = b;
- b = aux;
- }
- void ordenar_array (array<int,10>& a)
- {
- int j; int c=0; bool b = false;
- while (not b)
- {
- for (int i=0; i<9; i++)
- {
- if (a.at(i) > a.at(i+1))
- swap(a.at(i),a.at(i+1));
- c++;
- }
- for (j=0; j<9; j++)
- if (a.at(j) > a.at(j+1))
- {
- b = false;
- break;
- }
- if (j == 9)
- b = true;
- }
- cout << c << endl;
- }
- int main()
- {
- array<int,10> arr = {0,1,4,7,2,5,8,3,6,9};
- ordenar_array(arr);
- for (int i=0; i<10; i++)
- cout << arr.at(i) << ' ';
- cout << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement