binary tree deletion
C++
/* This is just the deletion function you need to write the required code.
Thank you. */
void deleteNode(Node *root, int data)
{
if(root == NULL)
{
cout << "Tree is empty\n";
return;
}
queue<Node*> q;
q.push(root);
while(!q.empty())
{
Node *temp = q.front();
q.pop();
if(temp->data == data)
{
Node *current = root;
Node *prev;
while(current->right != NULL)
{
prev = current;
current = current->right;
}
temp->data = current->data;
prev->right = NULL;
free(current);
cout << "Deleted\n";
return;
}
if(temp->left != NULL)
q.push(temp->left);
if(temp->right != NULL)
q.push(temp->right);
}
cout << "Node not found for deletion\n";
}
Also in C++:
- Title
- Qt asynchronous HTTP request
- Category
- C++
- Title
- object reference not set to an instance of an object c#
- Category
- C++
- Title
- Runtime Error: Runtime ErrorBad memory access (SIGBUS)
- Category
- C++
- Title
- log base 10 c+_+
- Category
- C++
- Title
- reverse a linked list using recursion
- Category
- C++
- Title
- binary exponentiation
- Category
- C++
- Title
- factorion
- Category
- C++
- Title
- variable sized arrays hackerrank solution in c++
- Category
- C++
- Title
- adding element in vector c++
- Category
- C++
- Title
- sort function in vector c++ stl
- Category
- C++
- Title
- how to dynamically allocate an array c++
- Category
- C++
- Title
- size of a matrix c++
- Category
- C++
- Title
- how to print 5 precision float in c++
- Category
- C++
- Title
- runtime array size c++
- Category
- C++
- Title
- binary tree search
- Category
- C++
- Title
- modulo c++
- Category
- C++
- Title
- typeid to string c++
- Category
- C++
- Title
- check if key exists in map c++
- Category
- C++
- Title
- initialize 2d array c++
- Category
- C++
- Title
- including cpp header file in c++
- Category
- C++
- Title
- how to get os name in c++
- Category
- C++
- Title
- how to check type in c++
- Category
- C++
- Title
- declaring 2d vector in c++
- Category
- C++
- Title
- double ended queue in c++ stl
- Category
- C++
- Title
- inserting an element in an set c++
- Category
- C++
- Title
- get elements of 2d array c++
- Category
- C++
- Title
- c++ throw exception
- Category
- C++
- Title
- flake8 max line length
- Category
- C++
- Title
- dfs in c++
- Category
- C++
- Title
- c++ function to find minimum element in array
- Category
- C++
- Title
- map insert c++
- Category
- C++
- Title
- converting char to int in c++
- Category
- C++
- Title
- erase in set
- Category
- C++
- Title
- find all the palindrome substring in a given string
- Category
- C++
- Title
- initialize int c++
- Category
- C++
- Title
- recursion in cpp with reference
- Category
- C++
- Title
- program to know if a number is prime
- Category
- C++
- Title
- how to sort a vector in c++
- Category
- C++
- Title
- c++ wait for user input
- Category
- C++
- Title
- c++ program to input and print text using Dynamic Memory Allocation.loop
- Category
- C++
- Title
- c++ sql
- Category
- C++
- Title
- C++ If
- Category
- C++
- Title
- c++ ambigous error
- Category
- C++
- Title
- iterate const vector
- Category
- C++
- Title
- c++ file to string
- Category
- C++
- Title
- quick sort predefined function in c++
- Category
- C++
- Title
- vector initialization c++
- Category
- C++
- Title
- what is iterator in c++?
- Category
- C++
- Title
- count function c++
- Category
- C++
- Title
- using namespace std in c++
- Category
- C++
- Title
- making random numbers in c++
- Category
- C++
- Title
- bellman ford algorithm cp algorithm
- Category
- C++
- Title
- how to declare a vector in c++
- Category
- C++
- Title
- c++ write new file
- Category
- C++
- Title
- c++ remove element from vector
- Category
- C++
- Title
- peak in c++
- Category
- C++
- Title
- how to output to console c++
- Category
- C++
- Title
- array as parameter c++
- Category
- C++
- Title
- find number of 1s in a binary cv::mat image
- Category
- C++
- Title
- c++ call method in same class
- Category
- C++
- Title
- is x prime?
- Category
- C++
- Title
- never gonna give you up lyrics
- Category
- C++
- Title
- sort function in c++
- Category
- C++
- Title
- c++ show time elapsed
- Category
- C++
- Title
- pionter in c++
- Category
- C++
- Title
- gfg left view of tree
- Category
- C++
- Title
- c++ ternary operator
- Category
- C++
- Title
- create new file c++
- Category
- C++
- Title
- hobo 8
- Category
- C++
- Title
- c++ iterate over vector
- Category
- C++
- Title
- Combination Sum
- Category
- C++
- Title
- c++ class member initialization
- Category
- C++
- Title
- appending a double to a string c++
- Category
- C++
- Title
- c++ while true loop
- Category
- C++
- Title
- glfw initialize in c++
- Category
- C++
- Title
- correct sequence of compilation process in c++
- Category
- C++
- Title
- c++ switch case statement
- Category
- C++
- Title
- formal parameter c++
- Category
- C++
- Title
- tokenize string c++
- Category
- C++
- Title
- border radius layout android xml
- Category
- C++
- Title
- c++ vector
- Category
- C++
- Title
- c++ initialization list
- Category
- C++
- Title
- cpp create lambda with recursion
- Category
- C++
- Title
- c++ sort
- Category
- C++
- Title
- expected initializer before 'isdigit'|
- Category
- C++
- Title
- how to import getline in c++
- Category
- C++
- Title
- c++ string^ to char*
- Category
- C++
- Title
- knapsack
- Category
- C++
- Title
- c++ sort array of ints
- Category
- C++
- Title
- c++ do while loop
- Category
- C++
- Title
- getting a random letter in c++
- Category
- C++
- Title
- c++ over load oprator to print variable of clas
- Category
- C++
- Title
- cube mapping sdl
- Category
- C++
- Title
- statement that causes a function to end in c++
- Category
- C++
- Title
- how to convert number to string
- Category
- C++
- Title
- Newton's sqrt in c++
- Category
- C++
- Title
- GetCurrentThreadId c
- Category
- C++
- Title
- equal elements in two arrays in c++
- Category
- C++
- Title
- c++ delete dynamically allocated array
- Category
- C++
- Title
- switch c++
- Category
- C++