Advertisement
ekzolot

Untitled

Oct 25th, 2021
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.97 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4. vector <int> merge_sort(vector <int>& a, int x, int y){
  5.     if (y-x<=1){
  6.         return a;
  7.     }
  8.     int m=(x+y)/2;
  9.     merge_sort (a, x, m);
  10.     merge_sort (a, m, y);
  11.     vector <int> merge(vector <int>& a, int x, int m, int y){
  12.     vector <int> result(y-x);
  13.     int i=x;
  14.     int j=m;
  15.     while (i<m && j<y){
  16.         if (a[i]<=a[j]){
  17.             result[i-x+j-m]=a[i];
  18.             i++;
  19.         }else{
  20.             result[i-x+j-m]=a[j];
  21.             j++;
  22.         }
  23.     }
  24.     while (i<m){
  25.         result[i-x+j-m]=a[i];
  26.         i++;
  27.  
  28.     }while (j<y){
  29.         result[i-x+j-m]=a[j];
  30.         j++;
  31.     }
  32.     return result;
  33.     }
  34.     for (int i=0; i<y; i++){
  35.         a[x+i]=result[i];
  36.     }
  37.     return a;
  38. }
  39. int main(){
  40.     int n;
  41.     cin>>n;
  42.     int x=0;
  43.     vector <int> a(n);
  44.     for (int i=0; i<n; i++){
  45.         cin>>a[i];
  46.     }
  47.     for (int i=0; i<n; i++){
  48.         cout<<a[i];
  49.     }
  50.  
  51. }
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement