sorting function in forward_alg.c and backward_alg.c to output same results