-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram38.cpp
More file actions
48 lines (36 loc) · 742 Bytes
/
program38.cpp
File metadata and controls
48 lines (36 loc) · 742 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
42
43
44
45
46
// REVERSE AN ARRAY USING VECTORS
#include<iostream>
#include<vector>
using namespace std;
vector<int>reverse(vector<int>v){
int s = 0;
int e = v.size() - 1;
while(s<=e)
{
swap(v[s],v[e]);
s++;
e--;
}
return v;
}
vector<int>print(vector<int>ans){
for(int i = 0;i<ans.size();i++)
{
cout<<ans[i]<<" ";
}
}
int main(){
vector<int>v;
v.push_back(45);
v.push_back(7);
v.push_back(56);
v.push_back(21);
v.push_back(76);
v.push_back(66);
cout<<"Before reversing the array : ";
print(v);
vector<int>ans = reverse(v);
cout<<"\nAfter reversing the array : ";
print(ans);
return 0;
}