Example #1
0
Leaf * IntervallTree_bed::srr(Leaf * &p1) {
	Leaf * p2;
	p2 = p1->right;
	p1->right = p2->left;
	p2->left = p1;
	p1->set_height(max(bsheight(p1->left), bsheight(p1->right)) + 1);
	p2->set_height(max(p1->get_height(), bsheight(p2->right)) + 1);
	return p2;
}
Example #2
0
nodeptr bstree:: srr(nodeptr &p1)
{
	nodeptr p2;
	p2 = p1->right;
	p1->right = p2->left;
	p2->left = p1;
	p1->height = max(bsheight(p1->left),bsheight(p1->right)) + 1;
	p2->height = max(p1->height,bsheight(p2->right)) + 1;
	return p2;
}
Example #3
0
// Inserting a node
void bstree::insert(int x,nodeptr &p)
{
	if (p == NULL)
	{
		p = new node;
		p->element = x;
		p->left=NULL;
		p->right = NULL;
		p->height=0;
		if (p==NULL)
			cout<<"\nOut of Space";
	}
	else
	{
		if (x<p->element)
		{
			insert(x,p->left);
			if ((bsheight(p->left) - bsheight(p->right))==2)
			{
				if (x < p->left->element)
					p=srl(p);
				else
					p = drl(p);
			}
		}
		else if (x>p->element)
		{
			insert(x,p->right);
			if ((bsheight(p->right) - bsheight(p->left))==2)
			{
				if (x > p->right->element)
					p=srr(p);
				else
					p = drr(p);
			}
		}
		else
			cout<<"\nElement Exists";
	}
	int m,n,d;
	m=bsheight(p->left);
	n=bsheight(p->right);
	d=max(m,n);
	p->height = d + 1;
}
Example #4
0
// Inserting a node
void IntervallTree_bed::insert(long start, long stop, Leaf *&p) {
	if (p == NULL) {
		p = new Leaf(start, stop);
		if (p == NULL) {
			std::cout << "Out of Space\n" << std::endl;
		}
	} else {

		long score = p->overlap(start, stop);

		if (score > 0) {
			insert(start, stop, p->left);
			if ((bsheight(p->left) - bsheight(p->right)) == 2) {
				score = p->left->overlap(start, stop);
				if (score > 0) {
					p = srl(p);
				} else {
					p = drl(p);
				}
			}
		} else if (score < 0) {
			insert(start, stop, p->right);
			if ((bsheight(p->right) - bsheight(p->left)) == 2) {
				score = p->right->overlap(start, stop);
				if (score < 0) {
					p = srr(p);
				} else {
					p = drr(p);
				}
			}
		} else { //overlaps!
			std::cerr << "Two regions overlap and are thus ignored:" << std::endl;
		}
	}
	int m, n, d;
	m = bsheight(p->left);
	n = bsheight(p->right);
	d = max(m, n);
	p->set_height(d + 1);
}