dumb implementations of each so far
This commit is contained in:
25
c/bubble_sort.c
Normal file
25
c/bubble_sort.c
Normal 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");
|
||||
}
|
||||
Reference in New Issue
Block a user