Welcome Guest [Log In] [Register]
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:

Username:   Password:
Add Reply
Removing leaf node
Topic Started: Nov 15 2013, 05:47 PM (106 Views)
Deleted User
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)
Quote Post Goto Top
 
Deleted User
Deleted User

you are not setting it to NULL
Quote Post Goto Top
 
Deleted User
Deleted User

I am.
Quote Post Goto Top
 
Deleted User
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.
Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Homework 6 · Next Topic »
Add Reply