diff --git a/bubblesort/main.c b/bubblesort/main.c new file mode 100644 index 0000000..378c05a --- /dev/null +++ b/bubblesort/main.c @@ -0,0 +1,49 @@ +#include +#include + +#define ARRAYLENGTH 100 + +void generateRandomArray(int *array) +{ + for (size_t i = 0; i < ARRAYLENGTH; i++) + { + array[i] = rand(); + } +} + +void printArrayContent(int *array) +{ + for (size_t i = 0; i < ARRAYLENGTH; i++) + { + printf("%d ", array[i]); + } + + printf("\n"); +} + +void sortArray(int *array) +{ + for (size_t i = 0; i < ARRAYLENGTH - 1; i++ ) + { + for (size_t j = 0; j < ARRAYLENGTH - 1 - i; j++) + { + if (array[j] > array[j+1]) + { + int temp = array[j+1]; + array[j+1] = array[j]; + array[j] = temp; + } + } + } +} + +int main(int argc, char *argv[]) +{ + int array[ARRAYLENGTH]; + + generateRandomArray(array); + sortArray(array); + printArrayContent(array); + + return 1; +} \ No newline at end of file diff --git a/readme.md b/readme.md index adc2807..79a566a 100644 --- a/readme.md +++ b/readme.md @@ -11,4 +11,4 @@ For my own personal revision, all implementations were initially attemped using ### Algorithms -- TBA +- [Bubble Sort](bubblesort\main.c)