Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "iostream"
- using namespace std;
- int main()
- {
- bool did_swap = true;
- int N = 8, index;
- /* A[0] will not be used */
- int A[9] = {0,98,23,45,14,6,67,33,42};
- int to_do = N-1;
- while( to_do > 0 && did_swap)
- {
- index = 1;
- did_swap = false;
- while ( index <= to_do )
- {
- if (A[index] > A[index+1])
- {
- int temp = A[index];
- A[index] = A[index+1];
- A[index+1] = temp;
- did_swap = true;
- }
- index = index+1;
- }
- cout << "to_do=" << to_do <<": ";
- for (int i = 1; i <= N; ++i)
- {
- cout<<A[i]<<" ";
- }
- cout << endl;
- to_do = to_do-1;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement