Bookmark Topic Watch Topic
  • New Topic

Question about binary tree delete method (non-API; hand-coded)  RSS feed

 
Gunslinger
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
  • Report post to moderator
I've got something that's been bugging me. For this binary tree deleteNode function, when a node is found, the method deleteFromTree is called on it. I understand everything, except: this may sound silly, but it seems that the method passes the target node on in a roundabout way. As you see, when found == true, we don't simply pass current as the method parameter, but rather tempCurrent.lLink or tempCurrent.rLink. Why is this? I know that there must be a reason that I'm not seeing (my text surely doesn't do it just for the heck of it), but it seems that this wastes computing time creating a reference to tempCurrent, then comparing it to deleteItem, then passing the appropriate child of tempCurrent to the deleteFromTree method, when current could simply be sent as the parameter, as it is the target node upon found == true. Thanks in advance!





deleteFromTree method:

 
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Report post to moderator
Lets continue in the other thread
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!