fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <iterator>
  4. int *reverse(int *arr, int size)
  5. {
  6. int *copyArray = new int[size];
  7. std::reverse_copy(arr, arr+size, copyArray);
  8. return copyArray;
  9. }
  10. int *expand(int *arr, int size)
  11. {
  12. int *newArray = new int[size * 2]();
  13. std::copy(arr, arr+size, newArray);
  14. return newArray;
  15. }
  16. int *shift(int *arr, int size)
  17. {
  18. int* newArray = new int [size + 1]();
  19. std::copy(arr, arr+size, newArray+1);
  20. return newArray;
  21. }
  22.  
  23. void display2(int arr[], int size)
  24. {
  25. std::copy(arr, arr+size, std::ostream_iterator<int>(std::cout, " "));
  26. std::cout << '\n';
  27. }
  28. int main()
  29. {
  30. int const SIZE = 5;
  31.  
  32. int myArray [SIZE] = {1, 2, 3, 4, 5};
  33. int *arraPtr = reverse(myArray, SIZE);
  34. display2(arraPtr, SIZE);
  35. delete [] arraPtr;
  36.  
  37. int myArray2 [SIZE] = {1, 2, 3, 4, 5};
  38. int *arraPtr2 = expand(myArray2, SIZE);
  39. display2(arraPtr2, SIZE*2);
  40. delete [] arraPtr2;
  41.  
  42. int myArray3 [SIZE] = {1, 2, 3, 4, 5};
  43. int *arraPtr3 = shift(myArray3, SIZE);
  44. display2(arraPtr3, SIZE+1);
  45. delete [] arraPtr3;
  46. }
  47.  
Success #stdin #stdout 0s 2856KB
stdin
Standard input is empty
stdout
5 4 3 2 1 
1 2 3 4 5 0 0 0 0 0 
0 1 2 3 4 5