Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int* shaker_sort(int* mas, int len){
- int right_index = (len - 1);
- int left_index = 0;
- int buf_1;
- int buf_2;
- while (left_index < right_index){
- for (int idx = left_index; idx < right_index; idx++){
- if (mas[idx+1] < mas[idx]){
- buf_1 = mas[idx];
- mas[idx] = mas[idx+1];
- mas[idx+1] = buf_1;
- }
- }
- right_index--;
- for (int idx = right_index; idx > left_index; idx--){
- if (mas[idx-1] > mas[idx]){
- buf_2 = mas[idx];
- mas[idx] = mas[idx-1];
- mas[idx-1] = buf_2;
- }
- }
- left_index++;
- }
- return mas;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement