Last active
December 29, 2020 10:51
-
-
Save ahmet-cetinkaya/edb03e53a5034f287b8ea0f9d458fc74 to your computer and use it in GitHub Desktop.
Sort algorithms - Bubble Sort
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
using namespace std; | |
main() | |
{ | |
int numbers[5] = { 10,1,53,5,8 }; | |
int length = sizeof(numbers) / sizeof(numbers[0]); | |
for (int i = 0; i < length; ++i) | |
for (int j = i + 1; j < length; ++j) | |
if (numbers[i] > numbers[j]) { | |
int temp = numbers[i]; | |
numbers[i] = numbers[j]; | |
numbers[j] = temp; | |
} | |
for (const int& n : numbers) cout << n << " "; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment