Files
aisd/insertion.c
T
2025-04-16 17:16:08 +02:00

26 lines
473 B
C

#include <stdio.h>
#include <stdlib.h>
// Capture the pipe of array contents, first number is the size
int main() {
int s;
scanf("%d", &s);
int *array = malloc(sizeof(int) * s);
for (int i = 0; i < s; i++) {
scanf("%d", &array[i]);
}
for (int j = 1; 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;
}