-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathstlAlgorithms.cpp
42 lines (33 loc) · 1.03 KB
/
stlAlgorithms.cpp
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
#include <algorithm>
#include <deque>
#include <iostream>
#include <list>
#include <string>
#include <vector>
template <typename Cont, typename T>
void doTheSame(Cont cont, T t){
for (auto c: cont) std::cout << c << " ";
std::cout << '\n';
std::cout << "cont.size(): " << cont.size() << '\n';
std::reverse(cont.begin(), cont.end());
for (auto c: cont) std::cout << c << " ";
std::cout << '\n';
std::reverse(cont.begin(), cont.end());
for (auto c: cont) std::cout << c << " ";
std::cout << '\n';
auto It= std::find(cont.begin(), cont.end(), t);
std::reverse(It, cont.end());
for (auto c: cont) std::cout << c << " ";
}
int main(){
std::cout << '\n';
std::vector<int> myVec{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
std::deque<std::string> myDeque({"A", "B", "C", "D", "E", "F", "G", "H", "I"});
std::list<char> myList({'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'});
doTheSame(myVec, 5);
std::cout << "\n\n";
doTheSame(myDeque, "D");
std::cout << "\n\n";
doTheSame(myList, 'd');
std::cout << "\n\n";
}