我正在尝试通过填写新的临时列表来对LinkedList进行排序。 它工作正常 - ' tempList'排序正确 - 但我如何引用其中的实际列表?
public class LinkedList implements AbstractListType {
public void addSorted(Object data){
/* */
}
public void sort(){
Node runpointer = first;
AbstractListType tempList = new LinkedList();
while(runpointer.next != null){
tempList.addSorted(runpointer.data);
runpointer = runpointer.next;
}
// tempList == this list //
}
答案 0 :(得分:0)
public class LinkedList implements AbstractListType {
public void addSorted(Object data){
/* */
}
public void sort(){
Node runpointer = first;
AbstractListType tempList = new LinkedList();
while(runpointer.next != null){
tempList.addSorted(runpointer.data);
runpointer = runpointer.next;
}
runpointer.head = tempList.head; // now your runpointer has the same list in the tempList
}