LinkedList按字母顺序排序

时间:2018-03-02 23:39:12

标签: java sorting linked-list alphabetical

我有一个Node类:

private class Node {
    private String data;
    private Node next;

    private Node(String data) {
        this.data = data;
    }
}

我需要按字母顺序排序,但不创建另一个链表或数组/ arraylist ...到目前为止我已经

Node current = head;
    String holder;
    boolean swap = true;

    while (swap){
        swap = false;
        while (current != null){
            if (current.data.compareTo(current.next.data) > 0){
                holder = current.data;
                current = current.next;
                current.next.data = holder;
                swap = true;
            }
        }
    }

我在current.next.data = hold;行上不断收到NullPointerException。任何建议或教程都将非常感谢。

1 个答案:

答案 0 :(得分:2)

不要重新发明轮子:

$("[id$='CustomFields.c.customer_type']").change(function(){
    StoreSectors();
});