-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path8_1.cpp
More file actions
55 lines (44 loc) · 1.21 KB
/
8_1.cpp
File metadata and controls
55 lines (44 loc) · 1.21 KB
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
49
50
51
52
53
54
55
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
void reverseWithStdReverse(vector<int>& sequence) {
reverse(sequence.begin(), sequence.end());
}
void reverseWithIterators(vector<int>& sequence) {
auto start = sequence.begin();
auto end = sequence.end() - 1;
while (start < end) {
iter_swap(start, end);
++start;
--end;
}
}
void printSequence(const vector<int>& sequence) {
for (int number : sequence) {
cout << number << " ";
}
cout << endl;
}
int main() {
vector<int> numbers;
int input;
cout << "Enter numbers (enter 0 to stop) :: ";
while (cin >> input && input != 0) {
numbers.push_back(input);
}
if (numbers.empty()) {
cout << "No numbers entered.\n";
return 0;
}
cout << "\nReversed using std::reverse:\n";
vector<int> method1 = numbers;
reverseWithStdReverse(method1);
printSequence(method1);
cout << "\nReversed using manual iterators:\n";
vector<int> method2 = numbers;
reverseWithIterators(method2);
printSequence(method2);
cout<<endl<<"24CE052_Pushtikansara"<<endl;
return 0;
}