> >>here is some psuedo code:
> >>
[quoted text clipped - 66 lines]
>
> can you show me a sample code?
public class objToBeCompared implements Comparable{
String a;
public int getObj{
return a;
}
public int compareTo(Object o){
String comp = o.getObj();
return this.getObj().compareTo(comp.getObj());
}
}
public class CompareStack{
public static void main (String [] args){
Stack stackOne = new Stack();
Stack stackTwo = new Stack();
for(int i = 0; i < args.length; i++){
stackOne.push(args[i]);
}
for(int i = args.length - 1; i > 0; i--){
stackTwo.push(args[i]);
}
//you can only look at the first object of a normal stack
//without removing anything
int compare = stackOne.peep().compareTo(stackTwo.peep());
//compare < 0 if stackOne is less
//compare = 0 if =
//compare > 0 if stackTwo is less
// Might want to check that with the API i always get it
//confused
}
}
i did not compile is so there might be some minor errors, but you get
the idea.
Ryan Stewart - 08 Dec 2004 12:02 GMT
[...]
> String a;
>
> public int getObj{
> return a;
> }
That won't work.
[...]
> int compare = stackOne.peep().compareTo(stackTwo.peep());
And neither will that. It's peek(), not peep(). Not to mentions that stack
returns Object, which doesn't implement Comparable. You'll have to cast or
use generics.
[...]
> i did not compile is so there might be some minor errors, but you get
> the idea.
It's always a good idea to compile before tossing code out. It only takes a
few seconds.