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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Need urgent help with tree

 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
First of all, sorry I've double posted(also in intermediate), but O really need to solve this before friday. Second, I'm not English so it may be quite difficult for me to explain exactly what my problem is, so I'll try to make it clear.

Ok, I'm first going to explain what I'm trying to do:
I'm writing this program where a user can add thousands of files(pictures), the objective of the program is to give a powerful search engine that finds "fast" the files wanted by the user. The part I'm wornking on now is search based on file size, I'm doing it whith AVL trees because this way I can easily search with querys like "size < 200".

Now the second part, the problem(I don't know if the sames names are given in English, I work with Nodes wich have a value, a right son and a left son):
I'm doing the add function to the tree recursively, but I've got lots of problems always with the same thing. I want to add a file to the tree, so I want to do it this way:
if(empty){
create Node
}else{
add(tree.right_son(),file)
}
Obviously this is not my java code, in case someone is going to tell me this is not java syntax.
The problem comes when tree.right_son() returns empty, it gives a NullPointer Exception, I know I could check if it is empty before calling the right_son() function, but I've got lots of function calls like this. What I need is being able to call a function with a null and then checking inside the function if the parameter is null, is there any way to do this, or does anybody know how to do this??

My real problem is that I'm "translating" this function in one I've got writen in C++, and that I have no time to do this, so any help will be really appreciated. Thanks a lot.
 
author & internet detective
Posts: 41184
848
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Note that we ask people not to cross post. It's pretty much the same people who read posts in both forums and invites repeated discussion. Please continue discussion in intermediate.
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic