Skip to content

Instantly share code, notes, and snippets.

@emadflash
Last active June 15, 2021 07:56
Show Gist options
  • Save emadflash/c311e9eba0f30df16ed171f06eae944b to your computer and use it in GitHub Desktop.
Save emadflash/c311e9eba0f30df16ed171f06eae944b to your computer and use it in GitHub Desktop.
#include <stdio.h>
void print_arr(int* a, int size) {
for(int i=0; i < size; ++i) {
printf("%d ", a[i]);
}
}
void bubble_sort(int* a, int size) {
for(int i=0; i < size; ++i) {
for(int j=i + 1; j < size; ++j) {
if (a[i] > a[j]) {
int temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
}
int main() {
int arr[] = { 1, 12, 9, 100, 8, 2, 4};
bubble_sort(arr, 7);
print_arr(arr, 7);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment