-
September 20th, 2013, 08:28 AM
#1
Problem With deleting Node in Trees
-
September 20th, 2013, 09:41 AM
#2
Re: Problem With deleting Node in Trees
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
September 20th, 2013, 09:50 AM
#3
Re: Problem With deleting Node in Trees
Originally Posted by N@R!MAN
I have Problems with deleting node in trees!my first problem is I don't understand the algorithm of deleting a node with two child!
If you didn't understand the algorithm, why did you write the code? You're supposed to understand fully what you are supposed to do before writing the code.
I write some kind of code that delete a node with two child but I think (maybe I should say I am sure ) that it has runtime or logical errors or something like that!
Of course it will crash.
Never write code that uses pointers, and not understand fully what you are coding. Otherwise you are almost guaranteed that the code will not work correctly!
my second problem is my code doesn't work if my node is root of tree!because I don't know if it is root what should be the parentPtr in my code!
Same thing here.
Before writing any code, use pencil and paper to design exactly what you need to do.
Regards,
Paul McKenzie
-
September 21st, 2013, 06:15 AM
#4
Re: Problem With deleting Node in Trees
Unless you need to write a node deletion routine for an assignemnt etc, one other approach is for each node to have a 'delete' flag which is normally clear and is set when the node key is 'deleted'. Search and print routines then ignore nodes that are 'flagged for deletion' and insert routines ignore the flag unless inserting the same key when the flag is simply cleared.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|