Sorting algorithm (C language implementation)