Skip to Content
C++ Data Structures and Algorithms
book

C++ Data Structures and Algorithms

by Wisnu Anggoro
April 2018
Intermediate to advanced content levelIntermediate to advanced
322 pages
6h 57m
English
Packt Publishing
Content preview from C++ Data Structures and Algorithms

Removing a given key

Removing a key in an AVL tree is also the same as removing a key in a BST. We also need to check the balance after removing the key. Here is the implementation of the Remove() operation in the AVL class, which has been updated with balance checking:

BSTNode * AVL::Remove(BSTNode * node, int key){    // The given node is    // not found in AVL tree    if (node == NULL)        return NULL;    // Target node is found    if (node->Key == key)    {        // If the node is a leaf node        // The node can be safely removed        if (node->Left == NULL && node->Right == NULL)            node = NULL;        // The node have only one child at right        else if (node->Left == NULL && node->Right != NULL)        {            // The only child will be connected to            // the parent's of node directly node->Right->Parent ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Data Structures and Algorithms Using C++

Data Structures and Algorithms Using C++

Ananda Rao Akepogu, Radhika Raju Palagiri
C++ Data Structures and Algorithm Design Principles

C++ Data Structures and Algorithm Design Principles

John Carey, Anil Achary, Shreyans Doshi, Payas Rajan
C++ Plus Data Structures, 6th Edition

C++ Plus Data Structures, 6th Edition

Nell Dale, Chip Weems, Tim Richards

Publisher Resources

ISBN: 9781788835213Supplemental Content