
#include <Rinternals.h>

#include "insertion_sort.h"
#include "merge_sort.h"

SEXP do_merge_sort(SEXP xp)
{
    int n = length(xp);
    SEXP yp = PROTECT(duplicate(xp));
    double *y = REAL(yp);
    merge_sort(y, 0, n-1);
    UNPROTECT(1);
    return yp;
}

SEXP do_insertion_sort(SEXP xp)
{
    int n = length(xp);
    SEXP yp = PROTECT(duplicate(xp));
    double *y = REAL(yp);
    insertion_sort(y, n);
    UNPROTECT(1);
    return yp;
}




