cOMS/sort/InsertionSort.h
Dennis Eichhorn 4f1cbd98f9
Some checks failed
Microsoft C++ Code Analysis / Analyze (push) Waiting to run
CodeQL / Analyze (${{ matrix.language }}) (autobuild, c-cpp) (push) Has been cancelled
started templating
2025-03-21 01:08:09 +00:00

16 lines
522 B
C

#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