r = true; break; case RH: rightBalance (root); taller = false; break; } } } } return true; } //在平衡二叉树中查找 data 结点, 并返回其地址 int *search (BSTree &root, int data) { if(root == NULL) { return NULL; } if(data == root->data) { return &root->data; } else if(data < root->data) { return search (root->lchild, data); } else { return search (root->rchild, data); } } // 中序遍历平衡二叉树 void inOrder (BSTree &root) { if(root) { inOrder (root->lchild); cout << root->data << "\t"; inOrder (root->rchild); } } //清空平衡二叉树 void clear (BSTree & root) { if(root) { clear (root->lchild); clear (root->rchild); free (root); } } int main () { BSTree root = NULL; int n; bool taller = false; printf ("请插入数据 ,输入0结束插入\n"); while(scanf ("%d", &n)) { if(n == 0) break; else insert (root, n, taller); } inOrder (root); return 0; }
调整平衡():先以20作为调整平衡最高结点 ,进行左旋,再以30作为调整平衡的最高结点,进行右旋。
|