std.sort

Function Description

The sort package provides sorting functions of the array type.

Based on the sorting mode, this package provides two sets of implementation: stable sorting and unstable sorting. During stable sorting, the sequence of equal elements remains unchanged before and after sorting. On the contrary, during unstable sorting, it is not ensured that the sequence of equal elements is consistent before and after sorting.

This package provides a group of generic sorting functions for sorting arrays with type T elements. Sorting requires elements to be comparable. Therefore, this group of functions is further classified into two categories: 1. The Comparable<T> interface needs to be implemented by T. 2. The T related compare function is transferred to a function as a parameter.

In addition, this package provides auxiliary interfaces SortByExtension(deprecated) and SortExtension(deprecated), which can be used to implement sorting-related functions of other types.

API List

Function

NameDescription
sort<T>(Array<T>, Bool, Bool) where T <: Comparable<T>Sorts an array. You can set the input parameters to specify whether to conduct stable sorting, and whether to do it in ascending or descending order.
sort<T>(Array<T>, (T, T) -> Ordering, Bool, Bool)Sorts an array using a comparison function. You can set the input parameters to specify whether to conduct stable sorting, and whether to do it in ascending or descending order.
sort<T>(Array<T>, (T, T) -> Bool, Bool, Bool)Sorts an array using a comparison function. You can set the input parameters to specify whether to conduct stable sorting, and whether to do it in ascending or descending order.
sort<T, K>(Array<T>, (T) -> K, Bool, Bool) where K <: Comparable<K>Sorts an array based on the specified keys (the keys can be compared with each other). You can set the input parameters to specify whether to conduct stable sorting, and whether to do it in ascending or descending order.
sort<T>(ArrayList<T>, Bool, Bool) where T <: Comparable<T>Sorts an ArrayList. You can set the input parameters to specify whether to conduct stable sorting, and whether to do it in ascending or descending order.
sort<T>(ArrayList<T>, (T, T) -> Ordering, Bool, Bool)Sorts an ArrayList using a comparison function. You can set the input parameters to specify whether to conduct stable sorting, and whether to do it in ascending or descending order.
sort<T>(ArrayList<T>, (T, T) -> Bool, Bool, Bool)Sorts an ArrayList using a comparison function. You can set the input parameters to specify whether to conduct stable sorting, and whether to do it in ascending or descending order.
sort<T, K>(ArrayList<T>, (T) -> K, Bool, Bool) where K <: Comparable<K>Sorts an ArrayList based on the specified keys (the keys can be compared with each other). You can set the input parameters to specify whether to conduct stable sorting, and whether to do it in ascending or descending order.
sort<T>(List<T>, Bool, Bool) where T <: Comparable<T>Sorts a List. You can set the input parameters to specify whether to conduct stable sorting, and whether to do it in ascending or descending order.
sort<T>(List<T>, (T, T) -> Ordering, Bool, Bool)Sorts a List using a comparison function. You can set the input parameters to specify whether to conduct stable sorting, and whether to do it in ascending or descending order.
sort<T>(List<T>, (T, T) -> Bool, Bool, Bool)Sorts a List using a comparison function. You can set the input parameters to specify whether to conduct stable sorting, and whether to do it in ascending or descending order.
sort<T, K>(List<T>, (T) -> K, Bool, Bool) where K <: Comparable<K>Sorts a List based on the specified keys (the keys can be compared with each other). You can set the input parameters to specify whether to conduct stable sorting, and whether to do it in ascending or descending order.
stableSort<T>(Array<T>) where T <: Comparable<T> (deprecated)Performs stable sorting on an array in ascending order.
stableSort<T>(Array<T>, (T, T) -> Ordering) (deprecated)Performs stable sorting on an array.
unstableSort<T>(Array<T>) where T <: Comparable<T> (deprecated)Performs unstable sorting on an array in ascending order.
unstableSort<T>(Array<T>, (T, T) -> Ordering) (deprecated)Performs unstable sorting on an array.

Interface

NameDescription
SortByExtension (deprecated)Serves as an auxiliary interface related to sorting. This interface is empty internally.
SortExtension (deprecated)Serves as an auxiliary interface related to sorting. This interface is empty internally.