C program for binary search tree deletion

C program for binary search tree deletion

Author: Hetwil On: 09.07.2017

Forum General Programming Boards C Programming Delete Binary Tree Node. Delete Binary Tree Node.

Program to insert and delete a node from the binary search tree - C Programming Examples and Tutorials

Thread Tools Show Printable Version Email this Page… Subscribe to this Thread… Search Thread. Hello, After about a week of trying to figure out how to write a function that would take into consideration all aspects of deleting a node from a binary tree After writing the function, I looked at it, and said to myself, "There has to be a way to make this easier to write and easier to read.

Computer Programming And Technology For Dummies: Insertion, Deletion And Traversal In Binary Search Tree

Below is the code: Doesn't this crash your program? Then you just pass either left or right. So it would be something like Code:.

c program for binary search tree deletion

If the root node only had one child and if the root node was the only node in the tree. When I performed a test, the program did crash, because parent was initialized to NULL. Once I took those cases into account, I changed the code a little bit and it all seems to be working ok now.

I see what your saying about reducing the code by using more functions, but I think I would have to implement more than one function in the case of: By far the greatest simplification you can make to that code would be to use recursion and have the code pass a pointer-to-a-pointer to the node rather then just a single-pointer, so that none of the code has to know whether the node being deleted comes from a left or a right of a node or from the root.

Instead it just NULLs whatever was passed in.

This is a minimal example to demonstrate that concept, and is meant to contain memory leaks etc, but the finished code needn't be more than about two to three times this size.

Last edited by iMalc; at Take only as directed - If symptoms persist, please see your debugger Linus Torvalds: The fact that everybody else does it some other way only means that they are wrong". When I started to think about how I could implement recursion, I came to a problem.

In my original code, I knew how to handle each case because I knew which node was the parent of the node I was going to delete.

When I think about using recursion, for example, if I had a sample tree: Binary Search Tree Delete Method By pobri19 in forum C Programming.

c program for binary search tree deletion

All times are GMT The time now is Search Engine Optimisation provided by DragonByte SEO v2.

inserted by FC2 system