|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
#1 |
|
Member (10 bit)
Join Date: Mar 2006
Location: Maryland
Posts: 550
|
Binary Search Tree Problem
So i've been enrolled in another computer science class and this one is about data structures and algorithms. We've been assigned a programming assignment to turn a completely unorganized/unstructured binary search tree into a balanced tree.
We're given 15 elements (I chose integers) and I decided to build a linear tree of those 15 integers. From there I'll have to pick the midpoint and then set that as a root and then perform a "rotate" to balance the tree out. I'm kind of stuck at the point where I'm building a linear tree. For some reason I cant figure out how to make each element point to the next... (i.e. 1 -> 2 -> 3 -> 4 -> ...) I've been able to assign the 1st integer to root and the 2nd to root.left but from that point I cant seem to figure out how to get the 3rd integer to be assigned to the 3rd left node in the tree and so on. Can someone provide me with an example in JAVA, not a pseudo code?
__________________
Kerberos2: Corsair Obsidian 700D ASUS M4A89TD Radeon HD 5850 A-DATA 8GB DDR3 1333 AMD Phenom II x6 1055T @ 2.8GHz w/ Corsair H50 Corsair 850HX PSU WD Blue 160GB 7200 RPM SATA HDD WD Black 640GB 7200 RPM SATA HDD ASUS DVD/CD Drive |
|
|
|
|
|
#2 |
|
Barefoot on the Moon!
Staff
Premium Member
Join Date: Aug 2002
Location: Northeastern USA
Posts: 13,385
|
This is a common problem/question, and you can find implementations of this sorting algorithm by googling for java and binary search.
If you have a problem with a specific piece of the code, feel free to post back here.
__________________
There are two secrets to staying young, being happy, and achieving success. You have to laugh and find humor every day, and you have to have a dream.
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|