Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Bubble sort like a boss
- */
- #include <iostream>
- using namespace std;
- void outputArray(int array[], int length);
- int main (){
- int myArray[] = {12,116,2,8,7,9,10,0,1,3,4,5};
- int length = sizeof(myArray) / sizeof(myArray[0]);
- outputArray(myArray, length);
- for (int j=0; j < length -1; ++j){
- for (int i=0; i < length - 1; ++i){
- if (myArray[i] > myArray[i+1]){
- int temp = myArray[i+1];
- myArray[i+1] = myArray[i];
- myArray[i] = temp;
- }
- }
- outputArray(myArray, length);
- }
- return 0;
- }
- void outputArray(int array[], int length){
- for (int i=0; i < length; ++i){
- cout << array[i] << " ";
- }
- cout << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement