// Insertion sort in C
#include <stdio.h>
// Function to print an array
void printArray(int array[], int size) {
for (int i = 0; i < size; i++) {
}
}
void insertionSort(int array[], int size) {
for (int step = 1; step < size; step++) {
int key = array[step];
int j = step - 1;
while (j >=0 && key < array[j]) {
array[j + 1] = array[j];
--j;
}
array[j + 1] = key;
}
}
// Driver code
int main() {
int data[] = {1000};
int size = sizeof(data) / sizeof(data[0]);
insertionSort(data, size);
printf("Sorted array in ascending order:\n"); printArray(data, size);
}
Ly8gSW5zZXJ0aW9uIHNvcnQgaW4gQwoKI2luY2x1ZGUgPHN0ZGlvLmg+CgovLyBGdW5jdGlvbiB0byBwcmludCBhbiBhcnJheQp2b2lkIHByaW50QXJyYXkoaW50IGFycmF5W10sIGludCBzaXplKSB7CiAgZm9yIChpbnQgaSA9IDA7IGkgPCBzaXplOyBpKyspIHsKICAgIHByaW50ZigiJWQgIiwgYXJyYXlbaV0pOwogIH0KICBwcmludGYoIlxuIik7Cn0KCnZvaWQgaW5zZXJ0aW9uU29ydChpbnQgYXJyYXlbXSwgaW50IHNpemUpIHsKICBmb3IgKGludCBzdGVwID0gMTsgc3RlcCA8IHNpemU7IHN0ZXArKykgewogICAgaW50IGtleSA9IGFycmF5W3N0ZXBdOwogICAgaW50IGogPSBzdGVwIC0gMTsKCiAKICAgIHdoaWxlIChqID49MCAmJiBrZXkgPCBhcnJheVtqXSkgewogICAgICBhcnJheVtqICsgMV0gPSBhcnJheVtqXTsKICAgICAgLS1qOwogICAgfQogICAgYXJyYXlbaiArIDFdID0ga2V5OwogIH0KfQoKLy8gRHJpdmVyIGNvZGUKaW50IG1haW4oKSB7CiAgaW50IGRhdGFbXSA9IHsxMDAwfTsKICBpbnQgc2l6ZSA9IHNpemVvZihkYXRhKSAvIHNpemVvZihkYXRhWzBdKTsKICBpbnNlcnRpb25Tb3J0KGRhdGEsIHNpemUpOwogIHByaW50ZigiU29ydGVkIGFycmF5IGluIGFzY2VuZGluZyBvcmRlcjpcbiIpOwogIHByaW50QXJyYXkoZGF0YSwgc2l6ZSk7Cn0=