This article presents a demo of an AVL Tree, which only describes inserting, removing, and searching a node. Originally, it was written with C, built by a DDK compiler, so it can be easily changed to adapt for a different driver.
Inserting a Node
There are two process to insert a node: First, the node is inserted into the tree as inserting it in a binary search tree. Second, balance the tree.
There are four rotate types to balance the tree. They are described in the following list:
Removing a Node
Removing a node is more complex than inserting one. You can find the theories about it on the Internet, so I needn't make any extra explanation about it here.
- Select the AvlTree->Demo to automatically generate an AVL Tree for viewing.
- Fill the edit box on the toolbar, and then select Insert or Remove. This will insert or remove the node from the tree.
By the way, please let me know if you have any questions or find bugs in the code!!