I'm trying to write a static sort class (for practice, I know that there is one already) that takes any ArrayList of comparable objects and sorts it. I've written a generic binary search tree before, but can't seem to get this started.
Is generic types even applicable here? I was also thinking that it could just take an ArrayList of Objects and that object's comparator so it could do the sort on different fields, but I'm not sure how to start that either. It's been a couple of years since I worked with this stuff and I'm trying to brush up, any help would be appreciated. Thanks. [ September 16, 2007: Message edited by: Lido Scaggsinsky ]
[Lido Scaggsinsky:]for practice, I know that there is one already
A comparison function, which imposes a total ordering on some collection of objects, can be passed to a sort method Collections.sort to allow precise control over the sort order. Comparators can also be used to control the order of certain data structures such as, TreeSet or TreeMap. This comparison method is placed in your class from Comparator.java describing the public interface java.util.Comparator<T> This generics stuff, I do not have a good handle on but always employs that double diamond notation, which allows the compiler to do compile time type checking. There is no RTTI in Java to speak of. ( and good riddiance in my mind right at the moment - though I will cycle through that again and again )
Which are described in C:\src_jdk1.5.0_12\java\util\Comparator.java
These methods have to be implemented in whatever it is you are trying to sort. If you have the methods written correctly, TreeMap and TreeSet will do the Red-Black implementation for you.
Originally posted by Nicholas Jordan: There is no RTTI in Java to speak of.
I presume what you mean is that Java erases generic types during compilation and hence generic type information is not available at run-time. But Java has a large amount of run-time type information available, via Reflection, instanceof etc. etc.
I don't know if you're thinking of C++ RTTI. If so, C++ without RTTI really does have no run-time type information at all. I don't know whether C++ with RTTI has run-time generic type information - does it? But Java has infinitely more run-time type information than C++ without RTTI. [ September 17, 2007: Message edited by: Peter Chase ]
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Well, I was trying to keep my post from running 1-10 k, which is not unusual for me. Shortly after the post I went looking in Class.java
To be sure, the RTTI ( in java ) is sophisticated, but consider the type resolution of an n-layered inheritance ( replete with changes in decision making to go along with it ) such as that proposed by Pat Farell:
I am still working on this concept challenge, from ai we know that if the number of dimensions in an n-dimensioned rises, the problem complexity rises at an exponential. IOW - beginner's all night hair puller on the 80-core thread allocation problem and maybe it will do some good, but what are you asking me ? [ September 17, 2007: Message edited by: Nicholas Jordan ]
"The differential equations that describe dynamic interactions of power generators are similar to that of the gravitational interplay among celestial bodies, which is chaotic in nature."
its a bit beyond what I've used generics for so was intersting to me to try it out - the following code may well have lots of things wrong with it as I've cobbled it together quickly from various sources, but it seems to work