Advertisement
Guest User

Untitled

a guest
May 1st, 2017
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #include <stdio.h>
  3. #include<stdlib.h>
  4. using namespace std;
  5. void twoWaySort(int arr[], int n)
  6. {
  7.     
  8.     int l = 0, r = n-1;
  9.  
  10.     
  11.     int k = 0;
  12.  
  13.     while (l < r)
  14.     {
  15.         while (arr[l]%2 != 0)
  16.         {
  17.             l++;
  18.             k++;
  19.         }
  20.          while (arr[r]%2 == 0  && l<r)
  21.             r--;
  22.  
  23.         if (l < r)
  24.             swap(arr[l], arr[r]);
  25.     }
  26.  
  27.     sort(arr, arr+k, greater<int>());
  28.  
  29.     
  30.     sort(arr+k, arr+n);
  31. }
  32.  
  33. int main()
  34. {
  35.     
  36.     int arr[][4]={
  37.                 {25,64,96,32},      
  38.                 {50,12,69,78},
  39.                 {12,14,65,89},
  40.                 {28,27,97,12}
  41.                               
  42.                 };
  43.     int i,k;
  44.     int n;
  45.     for(i=0;i<4;i++)
  46.     {for(n=0;n<4;n++)
  47.     {
  48.     printf("arr[%d][%d]",i,n);
  49.     scanf("%d%d",arr[i][n]);
  50.     }
  51.     }
  52.     system("cls");
  53.     twoWaySort(arr ,n);
  54.     for (int i=0; i<n; i++)
  55.         printf("%d\n",arr[i][n]);
  56.     system("pause");
  57.     return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement