avl tree implementation
1.0.0
C ++的AVL樹的實現,AVL樹是一種自動平衡的二進制搜索樹。該代碼包括以下功能:插入,刪除,搜索和打印。它具有功能齊全且受到良好的評價。
AVL樹是一種自動平衡的二進制搜索樹,每個節點的兩個子樹的高度最多都會有所不同。該實現提供了有效的方法,用於在樹內插入,刪除,搜索和打印元素。
insert功能使您可以在維護其平衡屬性的同時向AVL樹添加一個新值。
// Function
Node * insert (Node *node, int key);
// Example
AVLTree.insert(AVLTree.root, 19 );如果存在, deleteNode函數將從AVL樹中刪除一個值。此操作還確保樹保持平衡。如果發現並刪除了該值,則將樹的結構相應調整。
// Function
Node * deleteNode (Node *root, int key);
// Example
AVLTree.deleteNode(AVLTree.root, 16 );search功能在AVL樹中找到一個值,並打印其當前位置,父和孩子(如果有)。如果該值是根源的,則將表明這一點。
// Function
static void search (Node *root, int key);
// Example
Tree::search (AVLTree.root, 32 );
printTree功能以排序順序輸出AVL樹的元素。
// Function
void printTree (Node *root, int space);
// Example
AVLTree.printTree(AVLTree.root, 0 );