• 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

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi I've been working on building this binary search tree and have been looking at other examples on how to implement the tree according to what I was instructed. If someone could help me with some code or psuedocode on where to start making all my methods form the tree it would be a great help.
FileSystem


Filetree


Test
Node

 
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

If you have a binary search tree:-
Consider making the Node a private inner class in the Tree class. That is because you can consider a node to be part of a tree and not to be needed outside the tree. You can read about inner classes here.
When you create a new tree it has no nodes.
When you add your first value you create a new node often called root to contain it.
When you add subsequent values you consider whether they are greater or less than the value in the node and add them left or right accordingly.

I am not sure a file system matches a binary search because each level can contain an arbitrary number of elements whereas a binary tree usually contains up to two at each level. I think you need a Collection of nodes in each node; remember that a List would permit you to have two elements with the same name. You can move things up and down in Lists by removing and re‑inserting elements into the List.
 
Campbell Ritchie
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I added code tags to your post. Always use the tags: doesn't it look better now
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic