如何在数组中输入元素然后遍历它们?
答案 0 :(得分:0)
public LinkedList<T> sort() {
return sort(this.getNext());
}
public LinkedList<T> sort(LinkedList<T> head) {
if (head == null) {
this.setNext(null);
return this;
}
sortedHead = head.sort();
if (this.getData().compareTo(sortedHead.getData()) < 0) {
this.setNext(sortedHead);
return this;
} else {
sortedHead.setNext(this.sort(sortedHead.getNext()));
return sortedHead;
}
}