Compare commits

...

2 Commits

Author SHA1 Message Date
baz c4b219c556 Implement Bubble Sort 2024-01-29 16:42:31 +00:00
baz 4252fb6918 Add .gitignore 2024-01-29 16:39:15 +00:00
3 changed files with 52 additions and 1 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*.exe
.vscode

49
bubblesort/main.c Normal file
View File

@ -0,0 +1,49 @@
#include <stdio.h>
#include <stdlib.h>
#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;
}

View File

@ -11,4 +11,4 @@ For my own personal revision, all implementations were initially attemped using
### Algorithms ### Algorithms
- TBA - [Bubble Sort](bubblesort\main.c)