• Post Reply Bookmark Topic Watch Topic
  • New Topic

Binary Search Tree  RSS feed

 
Manny Walters
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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

 
Campbell Ritchie
Marshal
Posts: 56576
172
  • Mark post as helpful
  • send pies
  • 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: 56576
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I added code tags to your post. Always use the tags: doesn't it look better now
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!