kilolilo

Untitled

Nov 16th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. #include <iostream>
  2. int * sort(int old_arr[], int n){
  3.    int * a = new int[n];
  4.    for (int i = 0; i < n; i++){
  5.        *(a + i) = old_arr[i];
  6.    }
  7.    for(int i=0;i<n;i++){
  8.        for (int j=0;j<n-i-1;j++){
  9.            if(a[j]>a[j+1]){
  10.                int c=0;
  11.                c=a[j];
  12.                a[j]=a[j+1];
  13.                a[j+1]=c;
  14.            }
  15.        }
  16.    }
  17.    return a;
  18. }
  19.  
  20. using namespace std;
  21. int main()
  22. {
  23.     int n=5;
  24.     int a[n]={4,2,3,1,5};
  25.     int * res;
  26.     res = sort(a, n);
  27.     for (int i = 0; i < n; i++) cout << *(res + i) << "  ";
  28.     cout << endl;
  29.     delete [] res;
  30. }
Add Comment
Please, Sign In to add comment