Data Structure and Algorithm (C # Implementation) Series --- Avltree (2)
// --------------- Override --------------------
Public override void attachkey (Object _obj)
{
IF (! iSempty ())
Throw New Exception ("My: this node must be a empty tree node!");
THIS.KEY = _OBJ;
// Generate a DEGREE long array and initialize it to empty tree
THIS.TREELIST = New ArrayList ();
THIS.TREELIST.capacity = (int) this.degree;
For (INT i = 0; I { Treelist.add (new avltree ()); } // THIS.HEIGHT = 0; } // Balance the tree after the structure of the tree Public override void balance () { THIS.ADJUSTHEIGHT (); / / Greater than 1 means unbalanced IF (Math.Abs (this.balanceFactor ())> 1) { IF (this.balanceFactor ()> 0) { IF ((AVLTREE) THIS.LEFT) .balanceFactor ()> 0) THIS.llotation (); Else THIS.LRROTATION (); } Else { IF ((AVLTREE) THIS.right). barncefactor () <0) this.rrrotation (); Else this.Rlrotation (); } } } Public int Height {get {return this.Height;}} }