Skip to content

Instantly share code, notes, and snippets.

@RahulBRB
Created September 13, 2022 09:45
Show Gist options
  • Save RahulBRB/762caea0daae471406cf90d5e68f4610 to your computer and use it in GitHub Desktop.
Save RahulBRB/762caea0daae471406cf90d5e68f4610 to your computer and use it in GitHub Desktop.
This is the code for performing bubble sorting in C++
#include <iostream>
void sort(int array[], int size);
int main()
{
int array[] = {10, 1, 9, 2, 8, 3, 7, 4, 6, 5};
int size = sizeof(array)/sizeof(array[0]);
sort(array, size);
for(int element : array){
std::cout << element << " ";
}
return 0;
}
void sort(int array[], int size){
int temp;
for(int i = 0; i < size - 1; i++){
for(int j = 0; j < size - i - 1; j++){
if(array[j] > array[j + 1]){
temp = array[j];
array[j] = array[j + 1];
array[j + 1] = temp;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment