Quicksort and file rearrange

This commit is contained in:
2025-04-27 18:04:47 +02:00
parent 9180586d50
commit 1c8ab00c13
19 changed files with 316 additions and 168 deletions
+35
View File
@@ -0,0 +1,35 @@
#include <stdio.h>
#include <stdlib.h>
// Capture the pipe of array contents, first number is the size
int main() {
int s;
int res = scanf("%d", &s);
if (res != 1) {
fprintf(stderr, "Error reading size\n");
return 1;
}
int *array = malloc(sizeof(int) * s);
for (int i = 0; i < s; i++) {
res = scanf("%d", &array[i]);
if (res != 1) {
fprintf(stderr, "Error reading array element\n");
free(array);
return 1;
}
}
for (int j = 0; j < s; j++) {
int key = array[j];
int i = j - 1;
while (i >= 0 && array[i] > key) {
array[i + 1] = array[i];
i -= 1;
}
array[i + 1] = key;
}
free(array);
return 0;
}