forked from omonimus1/geeks-for-geeks-solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreverse-array-2.cpp
More file actions
41 lines (37 loc) · 771 Bytes
/
Copy pathreverse-array-2.cpp
File metadata and controls
41 lines (37 loc) · 771 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//https://practice.geeksforgeeks.org/problems/reverse-an-array/1/?track=DSASP-LinkedList&batchId=154
#include <bits/stdc++.h>
using namespace std;
void ReverseArray (int *arr, int len)
{
int start;
int end = len-1;
for(start = 0; start < len/2; start++)
{
swap(arr[start], arr[end]);
end--;
}
}
void PrintArray (int *arr, int len)
{
for(int i =0; i< len; i++)
cout << arr[i] << " ";
cout<<endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long int t;
int n;
cin >> t;
while(t--)
{
cin >> n;
int arr[n];
for(int i =0; i< n; i++)
cin >> arr[i];
ReverseArray(arr, n);
PrintArray(arr, n);
}
return 0;
}