Esempio n. 1
0
        private IntervalNode Find_Max(int x) //Find the Node with x-coordinate == x
        {
            IntervalNode node = root;

            while (node != null)
            {
                if (node.value == x)
                {
                    break;
                }
                if (x > node.value && node.right == null)
                {
                    return(node);
                }
                if (x > node.value)
                {
                    node = node.right;
                }
                else
                {
                    node = node.left;
                }
            }
            return(node);
        }
Esempio n. 2
0
        public List <Interval> Q(Interval interval1, Interval interval2) //find all points at rectangle [x1, x2]x[y1,y2]
        {
            IntervalNode node = Find_Max(interval1.y);

            List <Interval> result = node.Find_Points_In_Rectangle(interval1, interval2);

            return(result);
        }
Esempio n. 3
0
        private IntervalNode Build(int l, int r, IntervalNode node)
        {
            if (l > r)
            {
                return(null);
            }
            int mid   = (r + l) / 2;
            int value = sorted_list[mid].x;

            node = new IntervalNode();
            if (l == r)
            {
                node.value = value;
            }


            List <Interval> list = new List <Interval>();

            for (int i = 0; i < sorted_list.Count; i++)
            {
                if (sorted_list[i].x <= value)
                {
                    list.Add(sorted_list[i]);
                }
            }

            node.AddList(list);
            node.value = value;

            if (l == 0 && r == sorted_list.Count - 1)
            {
                root = node;
            }

            node.left  = Build(l, mid - 1, node.left);
            node.right = Build(mid + 1, r, node.right);

            return(node);
        }
Esempio n. 4
0
 public List <Interval> sorted_list = new List <Interval>(); //sorted by x-coordinate
 public RangeTree(List <Interval> list)
 {
     sorted_list = IntervalNode.SortByY(list, false);
     Build(0, sorted_list.Count - 1, root);
 }