Insertionsort Muster

Reading time ~1 minute

Framework für Insertionsort in C un

#include <stdio.h>
#include <string.h>
#include <inttypes.h>


extern  int64_t ins_asm (char * buffer);
        int64_t ins_c   (char * buffer);

int main(int argc, char const * argv[])
{
    char buffer1[]="Hallo Leute, was geht!?";
    char buffer2[]="Hallo Leute, was geht!?";

    ins_c(buffer1);
    ins_asm(buffer2);

    printf("%s\n", buffer1);
    printf("%s\n", buffer2);

    return 0;
}

int64_t ins_c(char * str)
{
    char x, len;
    size_t j;
    len = strlen(str);
    for (size_t i = 1; i < len; i++)
    {
        x = str[i];
        j = i-1;
        while (j >= 0 && str[j] > x)
        {
            str[j+1] = str[j];
            j--;
        }
        str[j+1] = x;
    }

    return 0;
}