Advertisement
Lisaveta777

Примитив

Dec 3rd, 2018
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.91 KB | None | 0 0
  1. //ПЕРВЫЙ ВАРИАНТ - всего один вложенный цикл, но формула в условии ИФ сложнее
  2.     for(i=0;i<s;i++)
  3.     {
  4.         for(j=i;j<s;j++)
  5.         {
  6.             if( (a[i]>a[j]&&i<start-1&& j<start) ||//first half of array
  7.                 (a[i]<a[j]&&i>=start-1&&j>=start)) //second half of array
  8.                 swap_2_els(a[i],a[j]);
  9.         }
  10.     }
  11.  
  12. //ВТОРОЙ ВАРИАНТ
  13.     for(i=0;i<start-1;i++)//first half of array, sort in ascending
  14.     {
  15.         for(j=i;j<start;j++)
  16.         {
  17.             if( a[i]>a[j])//
  18.             {
  19.                 swap_2_els(a[i],a[j]);
  20.             }
  21.         }
  22.     }
  23.     for(i=start;i<s-1;i++)//second half of array, sort in descending
  24.     {
  25.         for(j=i;j<s;j++)
  26.         {
  27.             if( a[i]<a[j] )//second part of array
  28.             {
  29.                 swap_2_els(s,a,i,j);
  30.             }
  31.         }
  32.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement