Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Binary Search Tree that prints values

 
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
 
Bartender
Posts: 10777
71
Hibernate Eclipse IDE 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
 
Ranch Hand
Posts: 954
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Aron, what is your thought on this?
 
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic