|
SortNthElementTKey, TValue Method (TKey, TValue, Int32, Boolean)
|
Retrieves the n-th smallest element in an array. See remarks for more info.
Namespace:
Accord
Assembly:
Accord.Math (in Accord.Math.dll) Version: 3.8.0
Syntax public static TKey NthElement<TKey, TValue>(
this TKey[] keys,
TValue[] items,
int n,
bool asc = true
)
where TKey : Object, IComparable<TKey>
<ExtensionAttribute>
Public Shared Function NthElement(Of TKey As {Object, IComparable(Of TKey)}, TValue) (
keys As TKey(),
items As TValue(),
n As Integer,
Optional asc As Boolean = true
) As TKey
Request Example
View SourceParameters
- keys
- Type: TKey
The keys that will be used to determine the order of elements in items. - items
- Type: TValue
The array of elements from which the n-th element should be extracted. - n
- Type: SystemInt32
The position to look for (0 returns the smallest element, 1 the second smallest, and so on). - asc (Optional)
- Type: SystemBoolean
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.
Type Parameters
- TKey
- The type for the keys associated with each value in the items array.
- TValue
- The type for the items in the array.
Return Value
Type:
TKeyIf
asc is true, returns the n-th smallest element in
the array. Otherwise, returns the n-th largest.
Usage Note
In Visual Basic and C#, you can call this method as an instance method on any object of type . When you use instance method syntax to call this method, omit the first parameter. For more information, see
Extension Methods (Visual Basic) or
Extension Methods (C# Programming Guide).
Remarks
As a side-effect, partially orders the collection, making sure every element smaller than the n-th
smaller element are in the beginning of the array (but not necessarily in order). If you need the
values that come before the n-th element to also be in order, please use the
PartialT(T, Int32, Boolean) method instead.
See Also