CircularListTSort(Int32, Int32, IComparerT) Method

Sorts the elements in a range of elements in CircularListT using the specified comparer.

Definition

Namespace: KGySoft.Collections
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 9.0.0
C#
public void Sort(
	int index,
	int count,
	IComparer<T>? comparer
)

Parameters

index  Int32
The zero-based starting index of the range to sort.
count  Int32
The length of the range to sort.
comparer  IComparerT
The IComparerT implementation to use when comparing elements, or to use the default comparer Default.

Remarks

If comparer is , then if T is an enum, this method uses the EnumComparer<TEnum>.Comparer; otherwise, the default comparer Comparer<T>.Default checks whether type T implements the IComparableT generic interface and uses that implementation, if available. If not, Comparer<T>.Default checks whether type T implements the IComparable interface. If type T does not implement either interface, Comparer<T>.Default throws an InvalidOperationException.

This implementation performs an unstable sort; that is, if two elements are equal, their order might not be preserved. In contrast, a stable sort preserves the order of elements that are equal.

On average, this method is an O(n log n) operation, where n is Count; in the worst case it is an O(n ^ 2) operation.

Exceptions

ArgumentOutOfRangeExceptionindex is less than 0.
-or-
count is less than 0.
ArgumentExceptionindex and count do not specify a valid range in the CircularListT.
-or-
countThe implementation of comparer caused an error during the sort.
InvalidOperationExceptioncomparer is , and the default comparer Default cannot find implementation of the IComparableT generic interface or the IComparable interface for type T.

See Also