-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path117rotatevector.cpp
More file actions
48 lines (37 loc) · 792 Bytes
/
Copy path117rotatevector.cpp
File metadata and controls
48 lines (37 loc) · 792 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
47
48
#include<iostream>
#include<vector>
using namespace std;
int main(){
vector<int> v = {1,2,3,4,5,6,7};
int r = 3;
int n = v.size();
r = r % n;
vector<int> temp(n);
for(int i = 0; i < n; i++){
temp[(i + r) % n] = v[i];
}
for(auto x : temp){
cout<<x << " ";
}
return 0;
}
/*
vector<int> temp;
// Step 1: Push last r elements
for(int i = n - r; i < n; i++) {
temp.push_back(v[i]);
}
// Step 2: Push remaining elements
for(int i = 0; i < n - r; i++) {
temp.push_back(v[i]);
}
// Print result
for(int x : temp)
cout << x << " ";
return 0;
*/
/*
reverse(nums.begin(), nums.end());
reverse(nums.begin(), nums.begin() + k);
reverse(nums.begin() + k, nums.end());
*/