Re: How do I use Comparators?

From: Tony Morris (
Date: 03/11/04

Date: Thu, 11 Mar 2004 19:32:48 +1000

"SA" <> wrote in message
> I will fully admit that I am doing an assignment BUT I'm not asking
> how to do
> it. I am writing a red-black tree class. The course I'm taking is data
> structures and algorithms using Java. Without telling you my entire
> history,
> I will just say I am taking this course, learning Java as I go.
> Anyway, I'm okay with creating the class and understand how the
> methods work. What I don't understand is the parameter we're to use.
> IE. the add method is:
> public boolean add(Comparable data){}
> What the heck is a Comparable? The text I have doesn't really have an
> explination and the java docs on don't really help either in
> this case.
> How do you traverse a tree to insert a node with a Comparable?
> IE. using an integer - if (this.value > node.value) {add(value,
> node.right)}
> How do you do that with only the one parameter, the Comparable!?

Have a read - that should be enough to stimulate some thoughts in your own
mind about how you go about using it to implement a tree.

Tony Morris
(BInfTech, Cert 3 I.T., SCJP[1.4], SCJD)
Software Engineer
IBM Australia - Tivoli Security Software
(2003 VTR1000F)

Relevant Pages

  • Re: Get reference to object in Set
    ... Java is that a Java char is 16 bits wide. ... Strings memoizing their hashes. ... patricia tree than using a HashMap or similar structure. ...
  • Re: database
    ... and Java. ... Binary trees have an elegant recursive pointer structure, ... Binary Tree Structure -- a quick introduction to binary ...
  • Re: How to develop without an IDE?
    ... Interestingly GNU make's large built in rule database does not contain anything related to compiling Java. ... other files that I want to 'update' in my tree. ... Here is a link showing Makefile for Java from the best book ... independent of what the IDE has. ...
  • Re: Beating a Dead Horse: NoClassDefFoundError
    ... > Thread model: posix ... > I've been doing java for a couple of days now, ... > public class hello ... IBM Australia - Tivoli Security Software ...
  • Re: Java Newbie challenge
    ... The java built in structures are, for example, all of the collection ... store a tree in RAM. ... You could use objects with a mother and father parent pointer. ...