SHARE
TWEET

Untitled

HellFinger May 25th, 2019 (edited) 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int* shaker_sort(int* mas, int len){
  2.  
  3.     int right_index = (len - 1);
  4.     int left_index = 0;
  5.  
  6.     int buf_1;
  7.     int buf_2;
  8.  
  9.  
  10.     while (left_index < right_index){
  11.         for (int idx = left_index; idx < right_index; idx++){
  12.             if (mas[idx+1] < mas[idx]){
  13.                 buf_1 = mas[idx];
  14.                 mas[idx] = mas[idx+1];
  15.                 mas[idx+1] = buf_1;
  16.             }
  17.         }
  18.         right_index--;
  19.  
  20.  
  21.         for (int idx = right_index; idx > left_index; idx--){
  22.             if (mas[idx-1] > mas[idx]){
  23.                 buf_2 = mas[idx];
  24.                 mas[idx] = mas[idx-1];
  25.                 mas[idx-1] = buf_2;
  26.             }
  27.         }
  28.         left_index++;
  29.     }
  30.     return mas;
  31. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top