Skip to content

Instantly share code, notes, and snippets.

@ahmet-cetinkaya
Last active December 29, 2020 10:51
Show Gist options
  • Save ahmet-cetinkaya/edb03e53a5034f287b8ea0f9d458fc74 to your computer and use it in GitHub Desktop.
Save ahmet-cetinkaya/edb03e53a5034f287b8ea0f9d458fc74 to your computer and use it in GitHub Desktop.
Sort algorithms - Bubble Sort
#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