Exemple #1
0
        private IntervalNode Build(int l, int r, IntervalNode node)
        {
            if (l >= r)
            {
                return(null);
            }
            int             mid = (l + r) / 2, i;
            List <Interval> list = new List <Interval>();

            for (i = 0; i < intervals_l.Count; i++)
            {
                if (mid < intervals_l[i].start)
                {
                    break;
                }
                if (Contains(mid, intervals_l[i]))
                {
                    list.Add(intervals_l[i]);
                }
            }
            node       = new IntervalNode(list);
            node.point = mid;
            if (l == min && r == max)
            {
                root = node;
            }

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

            return(node);
        }
Exemple #2
0
 public void PrintL(IntervalNode node)
 {
     Console.Write(node.point + "\t");
     if (node.left != null)
     {
         PrintL(node.left);
     }
     if (node.right != null)
     {
         PrintL(node.right);
     }
 }
Exemple #3
0
        public List <Interval> Q(int point, IntervalNode node)
        {
            if (point < node.leftIntervals[0].start)
            {
                return(Q(point, node.left));
            }
            if (point > node.rightIntervals[node.rightIntervals.Count - 1].end)
            {
                return(Q(point, node.right));
            }
            List <Interval> result = new List <Interval>();

            for (int i = 0; i < node.leftIntervals.Count; i++)
            {
                if (Contains(point, node.leftIntervals[i]))
                {
                    result.Add(node.leftIntervals[i]);
                }
            }
            return(result);
        }