QuickSort on Doubly Linked List

前端 未结 3 951
独厮守ぢ
独厮守ぢ 2021-01-21 10:46

I want to implement the QuickSort Algorithm on a sync Doubly Linked List. I give the function \"partition\" the left and right border, then it starts to search lower values on t

3条回答
  •  既然无缘
    2021-01-21 11:24

    Node partition(Node start, Node end){
        Node l = start;
        Node h = end.previous;
        Node pivot = end;
    
        if(end!=null && end.next!=start){ //Whenever deal with end.next, check null check
            while(h!=null && h.next!=l){//Whenever deal with end.next, check null check
                System.out.println("gumi");
                if(l.datapivot.data)
                    h=h.previous;
                else{
                    int temp = l.data;
                    l.data = h.data;
                    h.data = temp;
                }   
            }   
            int temp = pivot.data;
            pivot.data = l.data;
            l.data = temp;
        }
        return l;
    
    }
    void quicksort(Node start, Node end){
         System.out.println("jose");
       if(end!=null && end.next!=start ){ //Whenever deal with end.next, check null check , end should not be less than start: so the condition end.next!=start 
           System.out.println("Quixk");
           Node pivot = partition(start,end);
           quicksort(start, pivot.previous);
           quicksort(pivot.next, end);
       }
    
    }
    

提交回复
热议问题