| Welcome to UCR CS 14 Klefstad. You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free. Join our community! If you're already a member please log in to your account to access all of our features: |
| Removing leaf node | |
|---|---|
| Tweet Topic Started: Nov 15 2013, 05:47 PM (106 Views) | |
| Deleted User | Nov 15 2013, 05:47 PM Post #1 |
|
Deleted User
|
For some reason, when I try to print out tree with the leaf node removed the key is removed, however the info still remains. For example, when I print before removing: (alpha, 1) (charlie, 2) <-- root (delta, 1) Then after removing alpha: (,1) (charlie, 2) (delta, 1) |
|
|
| Deleted User | Nov 15 2013, 07:04 PM Post #2 |
|
Deleted User
|
you are not setting it to NULL |
|
|
| Deleted User | Nov 15 2013, 08:19 PM Post #3 |
|
Deleted User
|
I am. |
|
|
| Deleted User | Nov 15 2013, 08:51 PM Post #4 |
|
Deleted User
|
The only way I can see that happening is if charlie's left is still pointing to where alpha used to be. You deleted the node, yes. This means the string got destructed (became an empty string) but ints don't really have a destructor. This means that, if charlie's left is still pointing to where alpha used to be, when you dereference it, that stuff is still there. Said another way, there is still information for a TreeNode there since, until recently, there was one there. Thus we get the same number for info, but a blank string for key. This means you have a dangling pointer at charlie's left. If charlie's left is null you would have segfaulted if that ever got dereferenced. |
|
|
| 1 user reading this topic (1 Guest and 0 Anonymous) | |
| « Previous Topic · Homework 6 · Next Topic » |





12:15 PM Jul 11