
#include <Rcpp.h>

using namespace Rcpp;

void insertion_sort(NumericVector A)
{
    int j, i, n = A.length();
    double key;
    for (j = 1; j < n; j++)
    {
        key = A[j];
        i = j - 1;
        while (i > -1 && A[i] > key) {
	    A[i + 1] = A[i];
	    i = i - 1;
	}
	A[i + 1] = key;
    }
    return;
}

// [[Rcpp::export]]
NumericVector sort_vector(NumericVector x)
{
    int i, n = x.length();
    NumericVector xx(n);
    for (i = 0; i < n; i++) xx[i] = x[i];
    insertion_sort(xx);
    return xx;
}


