Created
September 13, 2022 09:45
-
-
Save RahulBRB/762caea0daae471406cf90d5e68f4610 to your computer and use it in GitHub Desktop.
This is the code for performing bubble sorting in C++
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> | |
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