Esempio n. 1
0
 /// <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);
         }
     }
 }
Esempio n. 2
0
        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));
            }
        }
Esempio n. 3
0
 public RankNode(int d)
 {
     this.data  = d;
     this.left  = null;
     this.right = null;
 }