cOMS/sort/InsertionSort.h
Dennis Eichhorn 39fbcf4300
Some checks are pending
CodeQL / Analyze (${{ matrix.language }}) (autobuild, c-cpp) (push) Waiting to run
Microsoft C++ Code Analysis / Analyze (push) Waiting to run
linux bug fixes
2025-03-22 01:10:19 +00:00

16 lines
522 B
C
Executable File

#ifndef COMS_SORT_Insertion_SORT_H
#define COMS_SORT_Insertion_SORT_H
#include "../stdlib/Types.h"
#include "../utils/Utils.h"
void insertionsort(void* arr, size_t num, size_t size, int32 (*compare)(const void* __restrict, const void* __restrict)) noexcept {
char* base = (char*) arr;
for (size_t i = 1; i < num; ++i) {
for (size_t j = i; j > 0 && compare(base + j * size, base + (j - 1) * size) < 0; --j) {
swap_memory(base + j * size, base + (j - 1) * size, size);
}
}
}
#endif