Advertisement
Schnuk

Untitled

Mar 2nd, 2021
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void reverse_1d_array(int* arr_begin, int* arr_end)
  6. {
  7.     if (arr_begin != nullptr && arr_end != nullptr)
  8.     {
  9.         int* firstPointer = arr_begin;
  10.         int* secondPointer = arr_end;
  11.         int arrSize = arr_end - arr_begin + 1;
  12.         for (int i = 0; i < arrSize / 2; i++)
  13.         {
  14.             int* temp = firstPointer;
  15.             firstPointer = secondPointer;
  16.             secondPointer = temp;
  17.             firstPointer--;
  18.             secondPointer++;
  19.         }
  20.     }
  21. }
  22.  
  23. int main()
  24. {
  25.     int arr[] = { 1, 3, 5, 7 };
  26.     int arrSize = sizeof(arr) / sizeof(arr[0]);
  27.     reverse_1d_array(&arr[0], &arr[arrSize - 1]);
  28.     cout << arr[0] << " " << arr[1] << " " << arr[2] << " " << arr[3];
  29. }
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement