[ create a new paste ] login | about

Link: http://codepad.org/HOsuYIdq    [ raw code | fork ]

scwizard - C++, pasted on Mar 7:
// Preorder "rotations" :O
// The results: http://img6.imageshack.us/img6/4388/oddrotations.png

// "Up" rotation.
if(x->prev != x->parent) {
	x->parent->rightchild = x->rightchild;
	if(x->parent->rightchild != nullptr) x->parent->rightchild->parent = x->parent;

	x->prev->leftchild = x;
	x->parent = x->prev;

	x->prev->rightchild = x->leftchild;
	if(x->leftchild != nullptr) x->prev->rightchild->parent = x->prev;

	x->rightchild = nullptr;
	x->leftchild = nullptr;
}

// "Down" rotation.
if(x.prev != x->parent) {
	// That conditional guarantees the existence of x->prev->prev.

	if(x->parent->leftchild = x) x->parent->leftchild = x->prev->prev;
	else x->parent->rightchild = x->prev->prev;
	x->prev->prev->parent = x->parent;

	x->prev->prev->rightchild = x;
	x->parent = x->prev->prev;

	x->prev->prev->leftchild = x->prev;
	x->prev->parent = x->prev->prev;

	x->prev->parent->leftchild = nullptr;
	x->prev->parent->rightchild = nullptr;
}


Create a new paste based on this one


Comments: