Skip to content

Instantly share code, notes, and snippets.

@czwen
Last active September 23, 2020 02:54
Show Gist options
  • Save czwen/44c6df6f41843f24f20d04a7b9559638 to your computer and use it in GitHub Desktop.
Save czwen/44c6df6f41843f24f20d04a7b9559638 to your computer and use it in GitHub Desktop.
#import <stdio.h>
void bubbleSort(int arr[], int length){
for (int i = 0; i < length-1; ++i)
{
for (int j = 0; j < length-1-i; ++j)
{
if (arr[j]>arr[j+1])
{
int temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
}
int main(){
int arr[] = {2,3,4,1,7,2,4,7,9};
int n = 9;
bubbleSort(arr, n);
for (int i = 0; i < n; ++i)
{
printf("%d\n", arr[i]);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment