This commit is contained in:
SinusFox
2023-06-06 08:25:30 +02:00
parent 5c0b4baf2b
commit 662edb7b2e
2 changed files with 33 additions and 0 deletions
+30
View File
@@ -0,0 +1,30 @@
// Bubblesort
#include "9_Num_Sort.h"
int main() {
// vars
int nums[MAXARR] = {12,15,17,6,2,4,7,6,3,10};
// sort
for (int max = sizeof(nums)/4 - 1; max >= 0; max--) {
//vars
int temp = 0;
// main loop
for (int i = 0; i < sizeof(nums)/4 - 1; i++) { // sizeof -> bytes, so divided by type size; -1 to avoid overflow
if (nums[i] > nums[i + 1]) {
temp = nums[i]; // switching the numbers
nums[i] = nums[i + 1];
nums[i + 1] = temp;
}
}
}
// output
for (int i = 0; i < sizeof(nums)/4; i++) { // sizeof -> bytes, so divided by type size; -1 to avoid overflow
printf("%i\n", nums[i]);
}
return 0;
}
+3
View File
@@ -0,0 +1,3 @@
#include <stdio.h>
#define MAXARR 10