There are many things wrong in this code. First of all, you're not respecting the Java conventions at all. Second, you're not using generics, as if we were still in 2004, when Java 5 didn't exist yet. Third, your class doesn't represent a tree, so it shouldn't be named mytree
. Fourth, your compareTo()
method is wrong. It's supposed to be symmetric:
A > B <==> B < A
If A and B's line[line_no]
are equal, then if you compare them with A.compareTo(B)
, the comparison method will return -1. And if you compare them with B.compareTo(A)
, it will return -1 as well. So you have A < B and B < A at the same time.