/// <summary> /// Inserts node into tree O(log n) /// </summary> /// <param name="d"></param> public void Insert(int d) { if (d <= this.data) { if (this.left != null) { this.left.Insert(d); } else { this.left = new RankNode(d); } this.leftSize++; } else { if (right != null) { this.right.Insert(d); } else { this.right = new RankNode(d); } } }
public static void Test() { RankNode n = new RankNode(5); for (int i = 0; i < 50; ++i) { n.Insert(i); } for (int i = 0; i < 50; ++i) { Console.WriteLine("Rank of " + i + " is " + n.GetRank(i)); } }
public RankNode(int d) { this.data = d; this.left = null; this.right = null; }