sort algorithm implementation