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;
}
CodePudding user response:
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.
CodePudding user response:
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