Its says

**"a flag is just an integer whose value is either true (1) or false(0). So create an int and set it to false before the inner loop starts, then if a swap is made set it to true. After the inner loop finishes check the value of that int and if it is true then break out of the outer loop. "**

Could someone show me how to do that, im pretty sure thats the difference between getting the output shown above as at the moment my ouput is just..

Data items in original order

2 6 4 8 10 12 89 68 45 37

Data items in ascending order

2 4 6 8 10 12 37 45 68 89

My code so far..

Expand|Select|Wrap|Line Numbers

- #include <iomanip>
- #include <iostream>
- using namespace std;
- using std::setw;
- main()
- {
- int numbers[10] = {2,6,4,8,10,12,89,68,45,37};
- int Swap;
- cout <<" Data items in original order\n";
- for(int ctr=0; ctr<10; ctr++)
- {
- cout<< setw(4) <<numbers[ctr];
- }
- cout<<"\n\n";
- for(int i=0; i<10; i++)
- for(int n=0; n<10; n++)
- if (numbers[n] > numbers[n + 1])
- {
- Swap = numbers[n];
- numbers[n] = numbers[n + 1];
- numbers[n + 1] = Swap;
- }
- cout<<"Data items in ascending order\n";
- for (int n=0; n<10; n++)
- cout<< setw(4) << numbers[n];
- cout<< endl <<endl;
- return 0;
- }