I saw some articles about the implementation of AVL’s rebalance() function.
After each insertion, we should check the insertion Node’s ancestors for balance.
So I think, in order to check ancestors’ balance, I got to know the insertion Node’s parent.
But, I wonder is there any other way to do that without having to use the parent pointer?
e.g., the node struct:
struct Node {
int data;
struct Node *lchild, *rchild; //*parent;
};
You can maintain a stack to the current node while you are traversing the tree
When you traverse to a new node, add it to the stack, and then you have your ancestry.
When you finish processing a node, pop it from the stack.
** Edit **
Elaboration for the alignment comment:
when creating children, do it this way: