Hakan Sözer

Yel Değirmenlerine Karşı Don Kişot Muyum?

insertion sort in c++ (link list based)

March15
//insertion sort method for link list. (click here to go link list)

void List::insertionSort(){
     Node *current;
     Node *nextCurrent;
     Node *temp;
     current = FirstItem->next;
     bool test = false;

     for(int i = 1; i < length; i++){
         temp = FirstItem;
         while(temp != current){
             nextCurrent = current->next;
             if(current->data < temp->data){
                 if(temp == FirstItem){
                     (current->prev)->next = current->next;
                     if(nextCurrent != NULL)
                     nextCurrent->prev = current->prev;
                     FirstItem = current;
                     current->prev = NULL;
                     current->next = temp;
                     temp->prev = current;
                 }
                 else{
                     (current->prev)->next = current->next;
                     if(nextCurrent != NULL)
                     nextCurrent->prev = current->prev;
                     (temp->prev)->next = current;
                     current->prev = temp->prev;
                     current->next = temp;
                     temp->prev = current;
                 }
                 test = true;
             } 

             temp = temp->next;
             if(test){
                 temp = current;
             }
         }
         test = false;
         current = nextCurrent;
     }
}

E-posta gizli kalacak.

Website örneği

Yorumunuz: