1// SPDX-FileCopyrightText: 2017-2020 TheAlgorithms and contributors
2// SPDX-FileCopyrightText: 2025 Sören Tempel <soeren+git@soeren-tempel.net>
3//
4// SPDX-License-Identifier: GPL-3.0-only
5
6#include <stddef.h>
7
8// Taken from: https://github.com/TheAlgorithms/C/blob/10d006c3b10340b901860e4810d2122b10e35b76/sorting/insertion_sort.c
9
10extern void quebex_symbolic_array(void *, size_t, size_t, const char *);
11
12#define MAX 7
13
14void insertionSort(unsigned char *arr, int size)
15{
16 for (int i = 1; i < size; i++)
17 {
18 int j = i - 1;
19 unsigned char key = arr[i];
20 /* Move all elements greater than key to one position */
21 while (j >= 0 && key < arr[j])
22 {
23 arr[j + 1] = arr[j];
24 j = j - 1;
25 }
26 /* Find a correct position for key */
27 arr[j + 1] = key;
28 }
29}
30
31int
32main(void)
33{
34 unsigned char array[MAX];
35
36 quebex_symbolic_array(array, MAX, sizeof(unsigned char), "array");
37 insertionSort(array, MAX);
38
39 return 0;
40}