• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Binary search tree remove node

 
Greenhorn
Posts: 3
Android Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi if someone can help me it would be great!!! Basically I have a remove method which removes a specified node but what the method is doing is deleting the entire tree. I tried debugging but I cant see the problem.
Here is my code...


 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, and welcome to the Ranch!

You say you tried debugging your code, but I don't see any println() calls that would be useful for that. Your first step should be to add a bunch to the remove method, to show what's happening at each step, what it's removing, and what the tree looks like before and after.
 
Ranch Hand
Posts: 88
Netbeans IDE Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That code is not compilable, so whatever you are running is not the code you posted.
 
Brian Lennon
Greenhorn
Posts: 3
Android Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry Mack I just had a look and here is the revised code


 
Mack Wilmot
Ranch Hand
Posts: 88
Netbeans IDE Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are assigning head.right = tail in your remove routine and when it goes to traverse() there is nothing to traverse. You are making t = tail on line 113. You essential disconnected the whole tree as far as traverse() is concerned. I think you need to start over on your removal routine and think through what you need to do step by step and write it down in pseudo code before you code it. Other than that, there are probably hundreds of examples on the Internet of binary tree operations you should look at.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic