'Why does this c# code has two angular bracket '>>' after IHeapifyable in this line
The method is in a class Heap which creates a Heap data structure in C# This method finds the Kth minimum value in O(K log n) time What does this line exactly do
List<IHeapifyable<K, D>> temp = new List<IHeapifyable<K, D>>();
Can someone explain this specific line in a C# code The whole code is over here
public IHeapifyable<K, D> KthMinElement(int k)
{
if (Count is 0) throw new InvalidOperationException();
if (k <= 0 || k > Count) throw new ArgumentOutOfRangeException();
IHeapifyable<K, D> kthMin = null;
List<IHeapifyable<K, D>> temp = new List<IHeapifyable<K, D>>();
for (int i = 1; i <= k; i++)
{
if (i == k) kthMin = data[1];
temp.Add(this.Delete());
}
foreach (var node in temp) this.Insert(node.Key, node.Data);
return kthMin;
}
Solution 1:[1]
The angle brackets are the opening and closing of what is contained in the data type they are describing.
List<IHeapifyable<K, D>> temp = new List<IHeapifyable<K, D>>();
So what this line says is: Create a List
data type containing one or more IHeapifyable<K,D>
data types and assign it to the variable temp
A List of integers is initialized with this
List<int>
Your example is the same except instead of int
it's
IHeaplifyable<K,D>
so if you replace the int
with IHeaplifyable
you get.
List<IHeaplifyable<K,D>>
Solution 2:[2]
The angle brackets are enclosing the generic type parameters. It's using a List<T>
where T
is IHeapifyable<K, D>
, so it's a List<IHeapifyable<K, D>>
. It's just like if you were to nest method calls like this:
Method1(Method2(arg));
so you end up with two closing parentheses at the end.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | John |