Advertisement
HellFinger

Untitled

May 25th, 2019
459
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.72 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement