Ejemplo n.º 1
0
 public void Insert(int d)
 {
     if (d <= data)
     {
         if (left != null)
         {
             left.Insert(d);
         }
         else
         {
             left = new RankNode(d);
         }
         left_size++;
     }
     else
     {
         if (right != null)
         {
             right.Insert(d);
         }
         else
         {
             right = new RankNode(d);
         }
     }
 }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            //EXAMPLE
            //Stream(in order of appearance):5, 1, 4, 4, 5, 9, 7, 13, 3
            //getRankOfNumber(l) 0
            //getRankOfNumber(3) 1
            //getRankOfNumber(4) 3


            List <int> btree = new List <int> {
                20, 15, 10, 5, 13, 25, 23, 24
            };
            RankNode r = new RankNode(17);

            foreach (var item in btree)
            {
                //r = new RankNode(item);
                r.Insert(item);
            }
            int itemtofind = 20;
            int rank       = r.GetRank(itemtofind);

            Console.WriteLine($"Rank if {itemtofind} is {rank}");
        }