#include <iostream>
usingnamespace std;
int main()
{
int myArray[10] = {0,1,2,3,4,5,6,7,8,9};
int swapFlag = 1; // flag=0 no swaps done set to 1 to start
int temp; // holds a number
// show the unsorted array
for (int i=0; i<10; i++)
{
cout << myArray[i] << " ";
}
cout << endl;
// do the sorting ...
swapFlag = 1;
while (swapFlag == 1) // while swaps have been done
{
swapFlag = 0; // set to no swaps
for (int i=0;i<9;i++) // not 9 not 10 because we look for i+1
{
if (myArray[i] < myArray[i+1]) // swap if current value is less than next value
{
temp = myArray[i];
myArray[i] = myArray[i+1];
myArray[i+1] = temp;
swapFlag = 1; // flag a swap took place
}
}
}
// sorting done print result
for (int i=0; i<10; i++)
{
cout << myArray[i] << " ";
}
cout << endl;
return 0;
}