Class Sort
Extension methods for sorting operations.
Inheritance
System.Object
Sort
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Assembly: Mars.Numerics.dll
Syntax
Methods
|
Improve this Doc
View Source
Insertion<T>(T[], Boolean)
Insertion sort.
Declaration
public static int Insertion<T>(T[] keys, bool asc = true)
where T : IComparable<T>
Parameters
Type |
Name |
Description |
T[] |
keys |
|
System.Boolean |
asc |
|
Returns
Type |
Description |
System.Int32 |
|
Type Parameters
|
Improve this Doc
View Source
Insertion<T>(T[], Func<T, T, Int32>, Boolean)
Insertion sort.
Declaration
public static int Insertion<T>(T[] keys, Func<T, T, int> comparer, bool asc = true)
Parameters
Type |
Name |
Description |
T[] |
keys |
|
System.Func<T, T, System.Int32> |
comparer |
|
System.Boolean |
asc |
|
Returns
Type |
Description |
System.Int32 |
|
Type Parameters
|
Improve this Doc
View Source
Insertion<T>(T[], Int32, Int32, Boolean)
Insertion sort.
Declaration
public static int Insertion<T>(T[] keys, int first, int last, bool asc = true)
where T : IComparable<T>
Parameters
Type |
Name |
Description |
T[] |
keys |
|
System.Int32 |
first |
|
System.Int32 |
last |
|
System.Boolean |
asc |
|
Returns
Type |
Description |
System.Int32 |
|
Type Parameters
|
Improve this Doc
View Source
Insertion<T>(T[], Int32, Int32, Func<T, T, Int32>, Boolean)
Insertion sort.
Declaration
public static int Insertion<T>(T[] keys, int first, int last, Func<T, T, int> comparer, bool asc = true)
Parameters
Type |
Name |
Description |
T[] |
keys |
|
System.Int32 |
first |
|
System.Int32 |
last |
|
System.Func<T, T, System.Int32> |
comparer |
|
System.Boolean |
asc |
|
Returns
Type |
Description |
System.Int32 |
|
Type Parameters
|
Improve this Doc
View Source
Insertion<T, TU>(T[], TU[], Boolean)
Insertion sort.
Declaration
public static int Insertion<T, TU>(T[] keys, TU[] items, bool asc = true)
where T : IComparable<T>
Parameters
Type |
Name |
Description |
T[] |
keys |
|
TU[] |
items |
|
System.Boolean |
asc |
|
Returns
Type |
Description |
System.Int32 |
|
Type Parameters
|
Improve this Doc
View Source
Insertion<TKey, TValue>(TKey[], TValue[], Func<TKey, TKey, Int32>, Boolean)
Insertion sort.
Declaration
public static int Insertion<TKey, TValue>(TKey[] keys, TValue[] items, Func<TKey, TKey, int> comparer, bool asc = true)
Parameters
Type |
Name |
Description |
TKey[] |
keys |
|
TValue[] |
items |
|
System.Func<TKey, TKey, System.Int32> |
comparer |
|
System.Boolean |
asc |
|
Returns
Type |
Description |
System.Int32 |
|
Type Parameters
Name |
Description |
TKey |
|
TValue |
|
|
Improve this Doc
View Source
Insertion<TKey, TValue>(TKey[], TValue[], Int32, Int32, Boolean)
Insertion sort.
Declaration
public static int Insertion<TKey, TValue>(TKey[] keys, TValue[] items, int first, int last, bool asc = true)
where TKey : IComparable<TKey>
Parameters
Type |
Name |
Description |
TKey[] |
keys |
|
TValue[] |
items |
|
System.Int32 |
first |
|
System.Int32 |
last |
|
System.Boolean |
asc |
|
Returns
Type |
Description |
System.Int32 |
|
Type Parameters
Name |
Description |
TKey |
|
TValue |
|
|
Improve this Doc
View Source
Insertion<TKeys, TValue>(TKeys[], TValue[], Int32, Int32, Func<TKeys, TKeys, Int32>, Boolean)
Insertion sort.
Declaration
public static int Insertion<TKeys, TValue>(TKeys[] keys, TValue[] items, int first, int last, Func<TKeys, TKeys, int> comparer, bool asc = true)
Parameters
Type |
Name |
Description |
TKeys[] |
keys |
|
TValue[] |
items |
|
System.Int32 |
first |
|
System.Int32 |
last |
|
System.Func<TKeys, TKeys, System.Int32> |
comparer |
|
System.Boolean |
asc |
|
Returns
Type |
Description |
System.Int32 |
|
Type Parameters
Name |
Description |
TKeys |
|
TValue |
|
|
Improve this Doc
View Source
NthElement<T>(T[], Int32, Boolean)
Retrieves the n-th smallest element in an array. See remarks for more info.
Declaration
public static T NthElement<T>(this T[] items, int n, bool asc = true)
where T : IComparable<T>
Parameters
Type |
Name |
Description |
T[] |
items |
The array of elements from which the n-th element should be extracted. |
System.Int32 |
n |
The position to look for (0 returns the smallest element, 1 the second smallest, and so on). |
System.Boolean |
asc |
Whether to take the smallest or the largest element. If set to false, instead
of returning the smallest, the method will return the largest elements.
|
Returns
Type |
Description |
T |
If asc is true, returns the n-th smallest element in
the array. Otherwise, returns the n-th largest.
|
Type Parameters
Name |
Description |
T |
The type for the items in the array. |
|
Improve this Doc
View Source
NthElement<T>(T[], Int32, Int32, Int32, Boolean)
Retrieves the n-th smallest element in an array. See remarks for more info.
Declaration
public static T NthElement<T>(this T[] items, int first, int last, int n, bool asc = true)
where T : IComparable<T>
Parameters
Type |
Name |
Description |
T[] |
items |
The array of elements from which the n-th element should be extracted. |
System.Int32 |
first |
The beginning of the search interval. |
System.Int32 |
last |
The end of the search interval. |
System.Int32 |
n |
The position to look for (0 returns the smallest element, 1 the second smallest, and so on). |
System.Boolean |
asc |
Whether to take the smallest or the largest element. If set to false, instead
of returning the smallest, the method will return the largest elements.
|
Returns
Type |
Description |
T |
If asc is true, returns the n-th smallest element in
the array. Otherwise, returns the n-th largest.
|
Type Parameters
Name |
Description |
T |
The type for the items in the array. |
|
Improve this Doc
View Source
NthElement<T>(T[], Int32, Int32, Int32, Func<T, T, Int32>, Boolean)
Retrieves the n-th smallest element in an array. See remarks for more info.
Declaration
public static T NthElement<T>(this T[] items, int first, int last, int n, Func<T, T, int> compare, bool asc = true)
Parameters
Type |
Name |
Description |
T[] |
items |
The array of elements from which the n-th element should be extracted. |
System.Int32 |
first |
The beginning of the search interval. |
System.Int32 |
last |
The end of the search interval. |
System.Int32 |
n |
The position to look for (0 returns the smallest element, 1 the second smallest, and so on). |
System.Func<T, T, System.Int32> |
compare |
The comparison function to be used to sort elements. |
System.Boolean |
asc |
Whether to take the smallest or the largest element. If set to false, instead
of returning the smallest, the method will return the largest elements.
|
Returns
Type |
Description |
T |
If asc is true, returns the n-th smallest element in
the array. Otherwise, returns the n-th largest.
|
Type Parameters
Name |
Description |
T |
The type for the items in the array. |
|
Improve this Doc
View Source
NthElement<TKey, TValue>(TKey[], TValue[], Int32, Boolean)
Retrieves the n-th smallest element in an array. See remarks for more info.
Declaration
public static TKey NthElement<TKey, TValue>(this TKey[] keys, TValue[] items, int n, bool asc = true)
where TKey : IComparable<TKey>
Parameters
Type |
Name |
Description |
TKey[] |
keys |
The keys that will be used to determine the order of elements in items . |
TValue[] |
items |
The array of elements from which the n-th element should be extracted. |
System.Int32 |
n |
The position to look for (0 returns the smallest element, 1 the second smallest, and so on). |
System.Boolean |
asc |
Whether to take the smallest or the largest element. If set to false, instead
of returning the smallest, the method will return the largest elements.
|
Returns
Type |
Description |
TKey |
If asc is true, returns the n-th smallest element in
the array. Otherwise, returns the n-th largest.
|
Type Parameters
Name |
Description |
TKey |
The type for the keys associated with each value in the items array. |
TValue |
The type for the items in the array. |
|
Improve this Doc
View Source
NthElement<TKey, TValue>(TKey[], TValue[], Int32, Int32, Int32, Boolean)
Retrieves the n-th smallest element in an array. See remarks for more info.
Declaration
public static TKey NthElement<TKey, TValue>(this TKey[] keys, TValue[] items, int first, int last, int n, bool asc = true)
where TKey : IComparable<TKey>
Parameters
Type |
Name |
Description |
TKey[] |
keys |
The keys that will be used to determine the order of elements in items . |
TValue[] |
items |
The array of elements from which the n-th element should be extracted. |
System.Int32 |
first |
The beginning of the search interval. |
System.Int32 |
last |
The end of the search interval. |
System.Int32 |
n |
The position to look for (0 returns the smallest element, 1 the second smallest, and so on). |
System.Boolean |
asc |
Whether to take the smallest or the largest element. If set to false, instead
of returning the smallest, the method will return the largest elements.
|
Returns
Type |
Description |
TKey |
If asc is true, returns the n-th smallest element in
the array. Otherwise, returns the n-th largest.
|
Type Parameters
Name |
Description |
TKey |
The type for the keys associated with each value in the items array. |
TValue |
The type for the items in the array. |
|
Improve this Doc
View Source
NthElement<TKey, TValue>(TKey[], TValue[], Int32, Int32, Int32, Func<TKey, TKey, Int32>, Boolean)
Retrieves the n-th smallest element in an array. See remarks for more info.
Declaration
public static TKey NthElement<TKey, TValue>(this TKey[] keys, TValue[] items, int first, int last, int n, Func<TKey, TKey, int> compare, bool asc = true)
Parameters
Type |
Name |
Description |
TKey[] |
keys |
The keys that will be used to determine the order of elements in items . |
TValue[] |
items |
The array of elements from which the n-th element should be extracted. |
System.Int32 |
first |
The beginning of the search interval. |
System.Int32 |
last |
The end of the search interval. |
System.Int32 |
n |
The position to look for (0 returns the smallest element, 1 the second smallest, and so on). |
System.Func<TKey, TKey, System.Int32> |
compare |
The comparison function to be used to sort elements. |
System.Boolean |
asc |
Whether to take the smallest or the largest element. If set to false, instead
of returning the smallest, the method will return the largest elements.
|
Returns
Type |
Description |
TKey |
If asc is true, returns the n-th smallest element in
the array. Otherwise, returns the n-th largest.
|
Type Parameters
Name |
Description |
TKey |
The type for the keys associated with each value in the items array. |
TValue |
The type for the items in the array. |
|
Improve this Doc
View Source
Partial<T>(T[], Int32, Boolean)
Partially orders a collection, making sure every element smaller
than the n-th smaller element are in the beginning of the array.
Declaration
public static void Partial<T>(T[] items, int n, bool asc = true)
where T : IComparable<T>
Parameters
Type |
Name |
Description |
T[] |
items |
The array of elements from which the n-th element should be extracted. |
System.Int32 |
n |
The position to look for (0 returns the smallest element, 1 the second smallest, and so on). |
System.Boolean |
asc |
Whether to take the smallest or the largest element. If set to false, instead
of returning the smallest, the method will return the largest elements in the beginning of the
array.
|
Type Parameters
Name |
Description |
T |
The type for the items in the array. |
|
Improve this Doc
View Source
Partial<TKey, TValue>(TKey[], TValue[], Int32, Boolean)
Partially orders a collection, making sure every element smaller
than the n-th smaller element are in the beginning of the array.
Declaration
public static void Partial<TKey, TValue>(TKey[] keys, TValue[] items, int n, bool asc = true)
where TKey : IComparable<TKey>
Parameters
Type |
Name |
Description |
TKey[] |
keys |
The keys that will be used to determine the order of elements in items . |
TValue[] |
items |
The array of elements from which the n-th element should be extracted. |
System.Int32 |
n |
The position to look for (0 returns the smallest element, 1 the second smallest, and so on). |
System.Boolean |
asc |
Whether to take the smallest or the largest element. If set to false, instead
of returning the smallest, the method will return the largest elements in the beginning of the
array.
|
Type Parameters
Name |
Description |
TKey |
The type for the keys associated with each value in the items array. |
TValue |
The type for the items in the array. |
|
Improve this Doc
View Source
Partition<T>(T[], Int32, Int32, Boolean)
Reorders the elements in the range [left, right) in such a way that all elements that
are smaller than the pivot precede those that are greater than the pivot. Relative order
of the elements is not preserved. This function should be equivalent to C++'s std::partition.
Declaration
public static int Partition<T>(this T[] keys, int first, int last, bool asc = true)
where T : IComparable<T>
Parameters
Type |
Name |
Description |
T[] |
keys |
The list to be reordered. |
System.Int32 |
first |
The beginning of the range to be reordered. |
System.Int32 |
last |
The end of the range to be reordered. |
System.Boolean |
asc |
Whether to sort in ascending or descending order. |
Returns
Type |
Description |
System.Int32 |
The index of the new pivot. |
Type Parameters
|
Improve this Doc
View Source
Partition<T>(T[], Int32, Int32, Func<T, T, Int32>, Boolean)
Reorders the elements in the range [left, right) in such a way that all elements for which
the function compare
returns true precede the elements for which compare
returns false. Relative order of the elements is not preserved. This function should be equivalent
to C++'s std::partition.
Declaration
public static int Partition<T>(this T[] items, int first, int last, Func<T, T, int> compare, bool asc = true)
Parameters
Type |
Name |
Description |
T[] |
items |
The list to be reordered. |
System.Int32 |
first |
The beginning of the range to be reordered. |
System.Int32 |
last |
The end of the range to be reordered. |
System.Func<T, T, System.Int32> |
compare |
Function to use in the comparison. |
System.Boolean |
asc |
Whether to sort in ascending or descending order. |
Returns
Type |
Description |
System.Int32 |
The index of the new pivot. |
Type Parameters
|
Improve this Doc
View Source
Partition<TKey, TValue>(TKey[], TValue[], Int32, Int32, Boolean)
Reorders the elements in the range [left, right) in such a way that all elements that
are smaller than the pivot precede those that are greater than the pivot. Relative order
of the elements is not preserved. This function should be equivalent to C++'s std::partition.
Declaration
public static int Partition<TKey, TValue>(this TKey[] keys, TValue[] items, int first, int last, bool asc = true)
where TKey : IComparable<TKey>
Parameters
Type |
Name |
Description |
TKey[] |
keys |
The list to be reordered. |
TValue[] |
items |
An array of keys associated with each element in the list. |
System.Int32 |
first |
The beginning of the range to be reordered. |
System.Int32 |
last |
The end of the range to be reordered. |
System.Boolean |
asc |
Whether to sort in ascending or descending order. |
Returns
Type |
Description |
System.Int32 |
The index of the new pivot. |
Type Parameters
Name |
Description |
TKey |
|
TValue |
|
|
Improve this Doc
View Source
Partition<TKey, TValue>(TKey[], TValue[], Int32, Int32, Func<TKey, TKey, Int32>, Boolean)
Reorders the elements in the range [left, right) in such a way that all elements for which
the function compare
returns true precede the elements for which compare
returns false. Relative order of the elements is not preserved. This function should be equivalent
to C++'s std::partition.
Declaration
public static int Partition<TKey, TValue>(this TKey[] keys, TValue[] items, int first, int last, Func<TKey, TKey, int> compare, bool asc = true)
Parameters
Type |
Name |
Description |
TKey[] |
keys |
The list to be reordered. |
TValue[] |
items |
An array of keys associated with each element in the list. |
System.Int32 |
first |
The beginning of the range to be reordered. |
System.Int32 |
last |
The end of the range to be reordered. |
System.Func<TKey, TKey, System.Int32> |
compare |
Function to use in the comparison. |
System.Boolean |
asc |
Whether to sort in ascending or descending order. |
Returns
Type |
Description |
System.Int32 |
The index of the new pivot. |
Type Parameters
Name |
Description |
TKey |
|
TValue |
|