recursion for sort.