Binary search tree c delete node

Binary search tree c delete node

Posted: WebNamo On: 26.05.2017

I have no problem with deletion methods. The left and right pointers are NULL when a new leaf added but when I use this function I see there is no deletion and this operation does not change the binary search tree.

C++ Delete node from binary search tree - Stack Overflow

What is that problem? Sign up for our newsletter and get our top new questions delivered to your inbox see an example. This answer was based on the assumption that the OP was concluding "there is no deletion" because he was expecting to see a NULL pointer in the calling location.

If that is not the case he will need to clarify what is leading to that conclusion. As is there is no reason to think the OP's code is not deleting whatever p points to. Therefore only a local copy of the pointer is set to NULL. Assuming you have code like this somewhere:.

Note that it is not necessary to test for NULL before calling delete. It will do so itself. And since p in deleteandnull is a local, there is no point to setting it to NULL.

So the whole code might as well be reduced to:. Prefer to use smart pointers, for instance as in the Boost library. By posting your answer, you agree to the privacy policy and terms of service. By subscribing, you agree to the privacy policy and terms of service. Stack Overflow Questions Developer Jobs Documentation beta Tags Users. Sign up or log in to customize your list. Tour Start here for a quick overview of the site Help New york stock exchange dividend stocks Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or binary search tree c delete node ads with us.

Log In Sign Up. Join the Stack Overflow Community.

Delete in Binary search tree in C - Stack Overflow

Stack Overflow is a community of 7. Join them; it only takes a minute: I have easy things to make out of legos binary search tree consists of nodes like: Kara 3, 8 33 Really, you should clear your mind up before asking questions here: Post some code how you are going to use this.

Hicham from CppDepend Team 4 Did you find this question interesting? Try our newsletter Sign up for our newsletter and get our top new questions delivered to your inbox see an example. Please click the link in the confirmation email to activate your subscription.

Assuming you have hull moving average bollinger bands like this somewhere: So the whole code might as well be reduced to: Steve Fallows 4, 4 34 At first locate the node to be deleted.

If the node is a leaf node: If the node is left child of the parentmake null the left pointer binary search tree c delete node its parent node and free the space for the node. If the node is right child of the parentmake null the right pointer of its parent node and free the space for the node. If the node has one child i.

binary search tree c delete node

If the node to be deleted is a left chile of its parentthen make link between the left pointer of its parent node and the child node to be deleted. Then delete the node. If the node to be deleted is a right child of its parentthen make link between the right pointer of its parent node and the child node to be deleted.

If the node to be deleted has two child: Locate the node with maximum value from the left sub-tree of the node to be deleted. Replace the node value to be deleted by the node found in step 4 i 5.

I already properly formatted my code. Please Focus on code not the format. If you find wrongyou will inform me. Sign up or log in StackExchange.

Sign up using Facebook. Sign up using Email and Password.

c++ delete in binary search tree - Stack Overflow

Post as a guest Name. In it, you'll get: The week's top questions and answers Important community announcements Questions that need answers.

Stack Overflow works best with JavaScript enabled. MathOverflow Mathematics Cross Validated stats Theoretical Computer Science Physics Chemistry Biology Computer Science Philosophy more 3. Meta Stack Exchange Stack Apps Area 51 Stack Overflow Talent.

inserted by FC2 system