balancing an AVL tree (C++)
I'm having the hardest time trying to figure out how to balance an AVL tree for my class. I've got it inserting with this: Node* Tree::insert(int d) { cout << "base insert\t" << d << endl; if (head == NULL) return (head = new Node(d)); else return insert(head, d); } Node* Tree::insert(Node*& current, int d) { cout << "insert\t" << d << endl; if (current == NULL) current = new Node(d); else if (d < current->data) { insert(current->lchild, d); if (height(current->lchild) - height(current->rchild)) { if (d < current->lchild->getData()) rotateLeftOnce(current); else rotateLeftTwice(current); } }