aspose file tools*
The moose likes Java in General and the fly likes Tournament Tree help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Tournament Tree help" Watch "Tournament Tree help" New topic
Author

Tournament Tree help

Christopher Beech
Ranch Hand

Joined: Feb 08, 2006
Posts: 40
Greetings, Java Ranch

I'm trying to type up a program that will generate sorted runs that are greater than the size of memory. The momory can hold a tournament tree with 4 elements. I have 16 elements to put in. It's suppose to take the 4 ints, do a min winner tree, toss the winner into an array, remove the winner from the tree, then insert a new given element. Program compares tree elements to the last int in the winner array. If the tree element is smaller than the last array in winner, it is ignored. Whenever all the tree elements are smaller than the last int in the winner array, the winner array is printed. The entire winner array is then erased.

Sorry if my code is a little funny. I've done most of the typing while sick.



Also, these three lines are giving the complier a fit:



[ March 27, 2007: Message edited by: Christopher Beech ]
[ March 27, 2007: Message edited by: Christopher Beech ]
Mike Mc Afee
Greenhorn

Joined: Jan 31, 2007
Posts: 19



Also, these three lines are giving the complier a fit:





Although no description of the kind of fit that the compiler was having is provided, I've taken a stab at what the problem is. In the future, the more description of the problem, the better.

getLeft and getRight appear to be returning type Node. Change left and right to type Node.

[ March 27, 2007: Message edited by: Mike Mc Afee ]
[ March 27, 2007: Message edited by: Mike Mc Afee ]
Christopher Beech
Ranch Hand

Joined: Feb 08, 2006
Posts: 40
Ok, did a little changing. Here's what I changed:



The compiler is having a fit over the following line:

h.compare();
Error: compare(Node) in Tournament cannot be applied to ();
[ March 27, 2007: Message edited by: Christopher Beech ]
David McCombs
Ranch Hand

Joined: Oct 17, 2006
Posts: 212
h.compare(); This is how you tried to call compare. This is the method:

public int compare(Node tNode)

You need to pass a Node as an argument.


"Should array indices start at 0 or 1? My compromise of 0.5 was rejected without, I thought, proper consideration."- Stan Kelly-Bootle
Christopher Beech
Ranch Hand

Joined: Feb 08, 2006
Posts: 40
New error found.


Missing return statement
David McCombs
Ranch Hand

Joined: Oct 17, 2006
Posts: 212
Look at the method header again. Then look at the end of the method, anything missing?
Christopher Beech
Ranch Hand

Joined: Feb 08, 2006
Posts: 40
It's expecting an int to be returned. But I'm not sure what int to return. I could put return smaller at the very end. That'll make the compiler happy, but I doubt it'll do any more than that.
Christopher Beech
Ranch Hand

Joined: Feb 08, 2006
Posts: 40
I've made some changes. I know that it will, at the very least, insert numbers in the correct order. If I could just get that compare to work.

Christopher Beech
Ranch Hand

Joined: Feb 08, 2006
Posts: 40
Anybody got an idea how to get the min-winner??? I've been at it all night but I've haven't gotten it yet.
Christopher Beech
Ranch Hand

Joined: Feb 08, 2006
Posts: 40
Wow. Almost no replies. I guess I should have known better than to expect help from an internet forum.

Thanks to the few that bother to help.
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3169
    
  10
If a method is not doing what you expect, then you need to debug it. At the very least put some print statements in which will show you the path it is taking thru the code.

Once you know what it is doing, if you can't see why it is doing this, come back and ask. Show us the test data you're using and describe which route thru the code you expect it to take and which route it is actually taking.

You say you've been at it all night. Well, tell us what you've found during this time, so we don't have to repeat all your tests. Debugging is time consuming. The less people have to do to help you, the more likely it is you'll get help.


Joanne
 
Don't get me started about those stupid light bulbs.
 
subject: Tournament Tree help
 
Similar Threads
Path of TreeSelectionEvent
Homework Trouble: Not understood syntax error, Instance of a generic BST class
scapegoat tree rebuilding...please help!
recursive method to balance a binary tree
lists inside a list :(((