[ create a new paste ] login | about

Link: http://codepad.org/JUNth3NB    [ raw code | output | fork ]

C, pasted on Jun 14:
int sort_quick(int low, int high, int *array) { // クイックソート 
  int i, // 対象要素の指標(先頭方向) 
      j, // 対象要素の指標(末尾方向) 
      mid, // 対象配列の中央の値=比較要素 
      tmp; // 入替え用 
  int count = 0;
  i = low;
  j = high;
  mid = array[(low + high) / 2]; // 比較要素 
  ++count;
  do{
   while(array[i] < mid)
     i++; // 比較要素より大きい要素を探索 
   while(mid < array[j])
     j--; // 比較要素より小さい要素を探索 
   if (i <= j){ // 2つの指標が交差するまで 
     tmp = array[i];
     ++count;
     array[i] = array[j]; // 大きい要素と小さい要素を交換 
     ++count;
     array[j] = tmp;
     ++count;
     i++;
     j--;
   }
  }while(i <= j);
   if (low < j)
     sort_quick(low, j, array); // 前半部についてソート 
   if (i < high)
     sort_quick(i, high, array); // 後半部についてソート
   return count;


Output:
1
2
In function 'sort_quick':
Line 31: error: expected declaration or statement at end of input


Create a new paste based on this one


Comments: