Collection Sorting
Sorting arranges collection elements in a specific order. Here we implement selection sort on an ArrayList<Int64>: iterate through the unsorted portion, find the minimum element, and swap it to the correct position.
The algorithm's core is two nested loops: the outer loop determines the current position, while the inner loop finds the index of the minimum value among the remaining elements. Once found, swap the current position with the minimum position. After completing one round, the current position holds the correct element.
Modifying the comparison condition (changing < to >) implements descending order sorting. Cangjie's standard library also provides more efficient sorting functions; here we use a basic algorithm to demonstrate sorting principles.
The code on the right implements ascending order sorting and displays the result.
Try modifying the code: change the comparison condition from < to > to implement descending order sorting.