fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4. template<typename T>
  5. void reverseArray(T *arr,int size) {
  6. T *swap;
  7. for (int i=0;i<size/2;i++) {
  8. swap=new T [size];
  9. swap[i]=arr[i];
  10. arr[i]=arr[size-1-i];
  11. arr[size-1-i]=swap[i];
  12. }
  13. }
  14. template<typename F>
  15. void printArray(F *arr,int size) {
  16. for (int i=0;i<size;i++) {
  17. cout<<arr[i]<<" ";
  18. }
  19. cout<<endl;
  20. }
  21. int main() {
  22. int arr[]={1,2,3,4};
  23. reverseArray(arr,4);
  24. printArray(arr,4);
  25. double arrd[]={3.08,4.72,2.00,3.21,10.90};
  26. reverseArray(arrd,5);
  27. printArray(arrd,5);
  28. char letter[]={'2','D','w'};
  29. reverseArray(letter,3);
  30. printArray(letter,3);
  31. string text[]={"hello world","kitten"};
  32. reverseArray(text,2);
  33. printArray(text,2);
  34. return 0;
  35. }
Success #stdin #stdout 0s 5288KB
stdin
Standard input is empty
stdout
4 3 2 1 
10.9 3.21 2 4.72 3.08 
w D 2 
kitten hello world