init
This commit is contained in:
+25
@@ -0,0 +1,25 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user