• Post Reply Bookmark Topic Watch Topic
  • New Topic

Binary Search Tree that prints values  RSS feed

 
Aron Silvester
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do you write a method that prints the contents of a tree from highest to lowest. Ex. 15, 13, 10, 8, 7, 3, 1.

My Node Class:



Cross post link here Binary Search Tree that prints values
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aron Silvester wrote:How do you write a method that prints the contents of a tree from highest to lowest. Ex. 15, 13, 10, 8, 7, 3, 1.

Well, first you probably need a method that can traverse the keys of your tree in reverse order. Have you tried that yet?

Winston
 
Tushar Goel
Ranch Hand
Posts: 934
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Aron, what is your thought on this?
 
Molayo Decker
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can try using the natural order in the collections framework or use array and iteration to achieve this. Depending on the list you have, just reversing it might not sort it from the highest to the lowest. You might want to swap the positions. Moving the lowest to the back and bring the highest in front. Which is a binary sort algorithm.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!