bubble sort implementation on linked lists

后端 未结 6 1424
小蘑菇
小蘑菇 2020-12-11 14:06

I have to implement a BubbleSort algorithm on a Linked List instead of an array. I\'m new to java so I don\'t really know how to put it in code. But I gave it a try and here

6条回答
  •  清歌不尽
    2020-12-11 14:30

    You need to implement the Comparable interface in the SinglyNode and use the string compare method inside the implementation. Something like:

    public void compareTo(SinglyNode node){
        return this.names.toString.compareTo(node.getNames().toString());
    }
    

    Or better just this.names.compareTo(node.getNames());

    However instead of just use Object class, I would the use Comparable interface for those wildcard objects.

提交回复
热议问题