如何在自身内部引用LinkedList



我正试图通过填充一个新的临时列表来对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 //
    }        
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
} 

相关内容

  • 没有找到相关文章

最新更新