Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- int * sort(int old_arr[], int n){
- int * a = new int[n];
- for (int i = 0; i < n; i++){
- *(a + i) = old_arr[i];
- }
- for(int i=0;i<n;i++){
- for (int j=0;j<n-i-1;j++){
- if(a[j]>a[j+1]){
- int c=0;
- c=a[j];
- a[j]=a[j+1];
- a[j+1]=c;
- }
- }
- }
- return a;
- }
- using namespace std;
- int main()
- {
- int n=5;
- int a[n]={4,2,3,1,5};
- int * res;
- res = sort(a, n);
- for (int i = 0; i < n; i++) cout << *(res + i) << " ";
- cout << endl;
- delete [] res;
- }
Add Comment
Please, Sign In to add comment