EzicMan

sortSliyaniyem

Jan 31st, 2019
103
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4. #include <algorithm>
  5. using namespace std;
  6.  
  7. typedef long long ll;
  8.  
  9. void sortPor(vector<ll>& a){
  10.     if(a.size() == 1){
  11.         return;
  12.     }
  13.     ll s = a.size() / 2;
  14.     vector<ll> a1(s);
  15.     vector<ll> a2(a.size() - s);
  16.     ll i = 0, j = 0, k = 0;
  17.     for (i = 0; i < s; i++) {
  18.         a1[i] = a[i];
  19.     }
  20.     for (j = 0; j < (a.size() - s); j++) {
  21.         a2[j] = a[i];
  22.         i++;
  23.     }
  24.     sortPor(a1);
  25.     sortPor(a2);
  26.     i = 0;
  27.     j = 0;
  28.     while (i < a1.size() && j < a2.size()) {
  29.         if (a1[i] <= a2[j]) {
  30.             a[k] = a1[i];
  31.             i++;
  32.         }
  33.         else {
  34.             a[k] = a2[j];
  35.             j++;
  36.         }
  37.         k++;
  38.     }
  39.     if (i != a1.size()) {
  40.         while (i < a1.size()) {
  41.             a[k] = a1[i];
  42.             i++;
  43.             k++;
  44.         }
  45.     }
  46.     if (j != a2.size()) {
  47.         while (j < a2.size()) {
  48.             a[k] = a2[j];
  49.             j++;
  50.             k++;
  51.         }
  52.     }
  53. }
  54.  
  55. int main(){
  56.     ll n;
  57.     cin >> n;
  58.     vector<ll> a(n);
  59.     for(ll i = 0; i < n; i++){
  60.         cin >> a[i];
  61.     }
  62.     sortPor(a);
  63.     for (ll i = 0; i < n; i++) {
  64.         cout << a[i] << " ";
  65.     }
  66.     return 0;
  67. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×