• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Tournament Tree help

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator




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
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Christopher Beech
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
New error found.


Missing return statement
 
David McCombs
Ranch Hand
Posts: 212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Look at the method header again. Then look at the end of the method, anything missing?
 
Christopher Beech
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic