Bulinna Berisha
Bulinna Berisha

Reputation: 9

How to make an ordered Linked List?

 public void sort1(){
    Comparator<OCell> byOrder = new Comparator<OCell>(){

        public int compare(OCell c1, OCell c2){
            return c1.getData() < c2.getData();
        }
    };
    Collections.sort(list, byOrder);
    print();
}
static OLinkedList<Integer> list = new OLinkedList<Integer>();

This is what I've come up so far but it's not working. Any help?

Upvotes: 0

Views: 71

Answers (1)

Edwin Dalorzo
Edwin Dalorzo

Reputation: 78579

A Comparator.compare method must return an integer, but your expression c1.getData() < c2.getData() is a boolean expression. You must fix your method, perhaps something as follows:

c1.getData() > c2.getData() ? 1 : (c1.getData() < c2.getData() ? -1 : 0)

Upvotes: 3

Related Questions