Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int array[10] = {4,3,11,9,7,54,12,35,31,1};
- cout << "The array's original order: ";
- for(int ac = 0;ac<9;ac++)
- {
- cout << array[ac] << ", ";
- }
- cout << endl;
- //##Bubble sort##
- int swapper;
- int swapped = 1;
- //do
- while (swapped = 1)
- {
- for (int sc=0;sc<8;sc++)
- {
- swapped = 0;
- if(array[sc] > array[sc+1])
- {
- swapper = array[sc];
- array[sc] = array[sc+1];
- array[sc+1] = swapper;
- swapped = 1;
- }
- cout << "here"; //continuously outputs this
- }
- }
- //while (swapped = 1);
- //##Sorted##
- cout << "The array sorted : ";
- for(int ac = 0;ac<9;ac++)
- {
- cout << array[ac] << ", ";
- }
- cout << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment