public void Insert(T priority, T1 item) { var node = new BinaryNodeValue <T, T1>(priority, item); items.Add(node); Upheap(items.Count - 1); }
void Upheap(int rank) { int parentRank = ParentRank(rank); if (parentRank < 0) { return; } BinaryNodeValue <T, T1> parent = items.ElementAt(parentRank), node = items.ElementAt(rank); //if (parent.Key <= node.Key) if (parent.Key.CompareTo(node.Key) <= 0) { return; } Swap(rank, parentRank); Upheap(parentRank); }