Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //ПЕРВЫЙ ВАРИАНТ - всего один вложенный цикл, но формула в условии ИФ сложнее
- for(i=0;i<s;i++)
- {
- for(j=i;j<s;j++)
- {
- if( (a[i]>a[j]&&i<start-1&& j<start) ||//first half of array
- (a[i]<a[j]&&i>=start-1&&j>=start)) //second half of array
- swap_2_els(a[i],a[j]);
- }
- }
- //ВТОРОЙ ВАРИАНТ
- for(i=0;i<start-1;i++)//first half of array, sort in ascending
- {
- for(j=i;j<start;j++)
- {
- if( a[i]>a[j])//
- {
- swap_2_els(a[i],a[j]);
- }
- }
- }
- for(i=start;i<s-1;i++)//second half of array, sort in descending
- {
- for(j=i;j<s;j++)
- {
- if( a[i]<a[j] )//second part of array
- {
- swap_2_els(s,a,i,j);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement