2016-08-17 16 views
0

まずを生成し、ここでのノード構造体です:この入力でバブルソートアルゴリズムは、誤った出力

void bubblesort(){ 
    bool unfinished = true; 
    node *temp= current; 
    current =first; 

    while(unfinished){ 
     unfinished = false; 

     while (current!=last){ 
      if (current->data > current->next->data){ 
       temp= current -> next; 
       current -> next =temp-> next; 
       temp-> previous = current -> previous; 
       current -> previous = n; 
       temp-> next = current; 
       unfinished = true; 

       if(current->previous==last) 
        {last = current; 
        last->next = NULL;} 
       if(current==first) 
        {first= current->previous; 
        first->previous=NULL;} 
      }else{ 
       current = current->next; 
      } 
     } 

}; 

struct node{ 
    double data; 
    node *next, *previous; 
}; 
struct node *first,*last,*current; 

は今ここにソート機能です

69.4637 -> 100.193 -> 136.683 -> 101.736 -> 115.222 -> 138.58 -> 90.3641 -> 101.509 -> 120.108 -> 129.731 -> 95.6236 -> 102.905 -> 89.0621 -> 94.345 -> 98.4529 -> 114.205 -> 129.379 -> 127.703 -> 92.5693 -> 88.4147 -> 125.005 -> 117.251 -> 104.636 -> 90.9676 -> 125.574 -> 134.147 -> 124.374 -> 116.539 -> 108.933 -> 82.3446 -> 124.502 -> 90.4727 -> 92.7035 -> 114.99 -> 114.87 -> 114.692 

私だけを取得しますこれを出力として取得します。

69.4637 -> 100.193 -> 136.683 -> 138.58 

どうなりますか?

+0

''現在で使用されるN 'どのようなものです - >前= N; '? – MikeCAT

+0

プログラムのデバッグ時に何を発見しましたか? –

+0

私には宿題のようです。 –

答えて

0
current -> previous = n; 

は本当にする必要があります:

current -> previous = temp;