Click or drag to resize
Accord.NET (logo)

SortNthElementTKey, TValue Method (TKey, TValue, Int32, Int32, Int32, Boolean)

Retrieves the n-th smallest element in an array. 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.

Namespace:  Accord
Assembly:  Accord.Math (in Accord.Math.dll) Version: 3.5.0
Syntax
public static TKey NthElement<TKey, TValue>(
	this TKey[] keys,
	TValue[] items,
	int first,
	int last,
	int n,
	bool asc = true
)
where TKey : Object, IComparable<TKey>
Request Example View Source

Parameters

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.
first
Type: SystemInt32
The beginning of the search interval.
last
Type: SystemInt32
The end of the search interval.
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: TKey
If 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).
See Also