dumb implementations of each so far

This commit is contained in:
2023-06-28 20:04:09 -07:00
parent 0b2c71d97d
commit 0763ca0cd4
6 changed files with 155 additions and 1 deletions

25
c/bubble_sort.c Normal file
View File

@@ -0,0 +1,25 @@
#include <stdio.h>
// asume the array is sorted of course
void bubble_sort(int arr[], int len) {
int temp;
for (int i = 0; i < len; i++) {
for (int j = 0; j < len - 1; j++) {
if (arr[j] > arr[j+1]) {
temp = arr[j+1];
arr[j+1] = arr[j];
arr[j] = temp;
}
}
}
}
int main() {
int arr[5] = {1, 3, 2, 4, 5};
bubble_sort(arr, 5);
for (int i = 0; i < 5; i++) {
printf("%d ", arr[i]);
}
printf("\n");
}