Beispiel #1
0
 public int GetRank(int d)
 {
     if (d == data)
     {
         return(left_size);
     }
     else if (d < data)
     {
         if (left == null)
         {
             return(-1);
         }
         else
         {
             return(left.GetRank(d));
         }
     }
     else
     {
         int right_rank = right == null ? -1 : right.GetRank(d);
         if (right_rank == -1)
         {
             return(-1);
         }
         else
         {
             return(left_size + 1 + right_rank);
         }
     }
 }
Beispiel #2
0
            public int GetRank(int d)
            {
                if (d == data)
                {
                    return(leftSize);
                }

                if (d < data)
                {
                    if (left == null)
                    {
                        return(-1);
                    }
                    else
                    {
                        left.GetRank(d);
                    }
                }
                else
                {
                    int rightRank = right?.GetRank(d) ?? -1;
                    if (rightRank == -1)
                    {
                        return(-1);
                    }

                    return(leftSize + 1 + rightRank);
                }
                throw new Exception("not valid");
            }
 public static int GetRankOfNumber(int number)
 {
     return(root.GetRank(number));
 }