function rightRotation(node) {
		var q = node, 
			p = node.left, 
			b, ah, bh, ch;
		if (!p) { return q; }   // No change
		b = p.right;
		// Alter tree structure
		if (q.parent) {
			p.parent = q.parent;
			if (q.parent.left === q) { q.parent.left = p; } else { q.parent.right = p; }
		} else {
			p.parent = null;
		}
		p.right = q;
		q.parent = p;
		q.left = b;
		if (b) { b.parent = q; }
		// Update heights
		ah = p.left ? p.left.height : 0;
		bh = b ? b.height : 0;
		ch = q.right ? q.right.height : 0;
		q.height = Math.max(bh, ch) + 1;
		p.height = Math.max(ah, q.height) + 1;
		return p;
	}
/**
	 * Performs a right rotation of the tree at the given node (if possible)
	 * Returns the root of the resulting tree
	 * The resulting tree's nodes' heights are also updated
	 */
Performs a right rotation of the tree at the given node (if possible)
Returns the root of the resulting tree
The resulting tree's nodes' heights are also updated
Performs a right rotation of the tree at the given node ( if possible ) Returns the root of the resulting tree The resulting tree ' s nodes ' heights are also updated
function rightRotation(node) {
		var q = node, 
			p = node.left, 
			b, ah, bh, ch;
		if (!p) { return q; }   
		b = p.right;
		if (q.parent) {
			p.parent = q.parent;
			if (q.parent.left === q) { q.parent.left = p; } else { q.parent.right = p; }
		} else {
			p.parent = null;
		}
		p.right = q;
		q.parent = p;
		q.left = b;
		if (b) { b.parent = q; }
		ah = p.left ? p.left.height : 0;
		bh = b ? b.height : 0;
		ch = q.right ? q.right.height : 0;
		q.height = Math.max(bh, ch) + 1;
		p.height = Math.max(ah, q.height) + 1;
		return p;
	}
function rightRotation ( node ) { var q = node , p = node . left , b , ah , bh , ch ; if ( ! p ) { return q ; } b = p . right ; if ( q . parent ) { p . parent = q . parent ; if ( q . parent . left === q ) { q . parent . left = p ; } else { q . parent . right = p ; } } else { p . parent = null ; } p . right = q ; q . parent = p ; q . left = b ; if ( b ) { b . parent = q ; } ah = p . left ? p . left . height : 0 ; bh = b ? b . height : 0 ; ch = q . right ? q . right . height : 0 ; q . height = Math . max ( bh , ch ) + 1 ; p . height = Math . max ( ah , q . height ) + 1 ; return p ; }
Performs a right rotation of the tree at the given node (if possible)
 Returns the root of the resulting tree
 The resulting tree's nodes' heights are also updated
Performs a right rotation of the tree at the given node ( if possible ) Returns the root of the resulting tree The resulting tree ' s nodes ' heights are also updated
// No change // Alter tree structure // Update heights