The sort algorithm