/*迭代器(iterator)和容器(STL)
*迭代器的类型为 Template <type>::iterator name,常用auto直接获取
*队列和栈不能遍历没有迭代器
*pair只能放一个元素没有迭代器
*/
# include <iostream>
# include <vector>
# include <list>
# include <map>
# include <stack>
# include <queue>
# include <set>
using namespace std;
class STL {
public:
//查看动态数组
void Show(vector<int> s) {
vector<int>::iterator it;
for (it = s.begin(); it != s.end(); it++){
cout << *it << " ";
}
cout << endl;
}
//查看链表
void Show(list<int> s) {
for (auto it = s.begin(); it != s.end(); it++){
cout << *it << " ";
}
cout << endl;
}
//查看映射
void Show(map<int , char> s) {
for (auto it = s.begin(); it != s.end(); it++){
cout << it->first << " : " << it->second << endl;
}
}
//查看集合
void Show(set<int> s){
for (auto it = s.begin(); it != s.end(); it++){
cout << *it << " ";
}
cout << endl;
}
//查看pair
void Show(pair<int , char> s) {
cout << s.first << " : " << s.second << endl;
}
//查看队列
void Show(queue<int> s){
cout << "队首 : " << s.front() << endl;
cout << "队尾 : " << s.back() << endl;
}
//查看栈
void Show(stack<int> s) {
cout <<"栈顶 : " << s.top()<< endl;
}
};
int main()
{
STL s;
vector<int> v;
v.push_back(3);
v.push_back(4);
v.push_back(5);
v.push_back(6);
s.Show(v);
cout << "-----------" << endl;
list <int> l;
l.push_back(15);
l.push_front(14);
l.push_front(13);
l.push_back(16);
s.Show(l);
cout << "-----------" << endl;
map<int , char> m;
m.insert({1,'a'});
m.insert({2,'b'});
m.insert({3,'c'});
m.insert({4,'d'});
s.Show(m);
cout << "-----------" << endl;
pair<int,char> p;
p = make_pair(5,'e');
m.insert(p);
s.Show(p);
cout << "-----" << endl;
s.Show(m);
cout << "-----------" << endl;
stack <int> s1;
s1.push(21);
s1.push(22);
s1.push(23);
s1.push(24);
s1.push(25);
s.Show(s1);
cout << "-----------" << endl;
queue<int> q;
q.push(31);
q.push(32);
q.push(33);
q.push(34);
s.Show(q);
cout << "-----------" << endl;
set<int>s2;
s2 = {41,42,43,44,45,46,47,48,49};
s.Show(s2);
cout << "-----------" << endl;
}
/*迭代器(iterator)和容器(STL)
*迭代器的类型为 Template <type>::iterator name,常用auto直接获取
*队列和栈不能遍历没有迭代器
*pair只能放一个元素没有迭代器
*/
# include <iostream>
# include <vector>
# include <list>
# include <map>
# include <stack>
# include <queue>
# include <set>
using namespace std;
class STL {
public:
//查看动态数组
void Show(vector<int> s) {
for (auto it = s.begin(); it != s.end(); it++){
cout << *it << " ";
}
cout << endl;
}
//查看链表
void Show(list<int> s) {
for (auto it = s.begin(); it != s.end(); it++){
cout << *it << " ";
}
cout << endl;
}
//查看映射
void Show(map<int , char> s) {
for (auto it = s.begin(); it != s.end(); it++){
cout << it->first << " : " << it->second << endl;
}
}
//查看集合
void Show(set<int> s){
for (auto it = s.begin(); it != s.end(); it++){
cout << *it << " ";
}
cout << endl;
}
//查看pair
void Show(pair<int , char> s) {
cout << s.first << " : " << s.second << endl;
}
//查看队列
void Show(queue<int> s){
cout << "队首 : " << s.front() << endl;
cout << "队尾 : " << s.back() << endl;
}
//查看栈
void Show(stack<int> s) {
cout <<"栈顶 : " << s.top()<< endl;
}
};
int main()
{
STL s;
vector<int> v;
v.push_back(3);
v.push_back(4);
v.push_back(5);
v.push_back(6);
s.Show(v);
cout << "-----------" << endl;
list <int> l;
l.push_back(15);
l.push_front(14);
l.push_front(13);
l.push_back(16);
s.Show(l);
cout << "-----------" << endl;
map<int , char> m;
m.insert({1,'a'});
m.insert({2,'b'});
m.insert({3,'c'});
m.insert({4,'d'});
s.Show(m);
cout << "-----------" << endl;
pair<int,char> p;
p = make_pair(5,'e');
m.insert(p);
s.Show(p);
cout << "-----" << endl;
s.Show(m);
cout << "-----------" << endl;
stack <int> s1;
s1.push(21);
s1.push(22);
s1.push(23);
s1.push(24);
s1.push(25);
s.Show(s1);
cout << "-----------" << endl;
queue<int> q;
q.push(31);
q.push(32);
q.push(33);
q.push(34);
s.Show(q);
cout << "-----------" << endl;
set<int>s2;
s2 = {41,42,43,44,45,46,47,48,49};
s.Show(s2);
cout << "-----------" << endl;
}
*迭代器的类型为 Template <type>::iterator name,常用auto直接获取
*队列和栈不能遍历没有迭代器
*pair只能放一个元素没有迭代器
*/
# include <iostream>
# include <vector>
# include <list>
# include <map>
# include <stack>
# include <queue>
# include <set>
using namespace std;
class STL {
public:
//查看动态数组
void Show(vector<int> s) {
vector<int>::iterator it;
for (it = s.begin(); it != s.end(); it++){
cout << *it << " ";
}
cout << endl;
}
//查看链表
void Show(list<int> s) {
for (auto it = s.begin(); it != s.end(); it++){
cout << *it << " ";
}
cout << endl;
}
//查看映射
void Show(map<int , char> s) {
for (auto it = s.begin(); it != s.end(); it++){
cout << it->first << " : " << it->second << endl;
}
}
//查看集合
void Show(set<int> s){
for (auto it = s.begin(); it != s.end(); it++){
cout << *it << " ";
}
cout << endl;
}
//查看pair
void Show(pair<int , char> s) {
cout << s.first << " : " << s.second << endl;
}
//查看队列
void Show(queue<int> s){
cout << "队首 : " << s.front() << endl;
cout << "队尾 : " << s.back() << endl;
}
//查看栈
void Show(stack<int> s) {
cout <<"栈顶 : " << s.top()<< endl;
}
};
int main()
{
STL s;
vector<int> v;
v.push_back(3);
v.push_back(4);
v.push_back(5);
v.push_back(6);
s.Show(v);
cout << "-----------" << endl;
list <int> l;
l.push_back(15);
l.push_front(14);
l.push_front(13);
l.push_back(16);
s.Show(l);
cout << "-----------" << endl;
map<int , char> m;
m.insert({1,'a'});
m.insert({2,'b'});
m.insert({3,'c'});
m.insert({4,'d'});
s.Show(m);
cout << "-----------" << endl;
pair<int,char> p;
p = make_pair(5,'e');
m.insert(p);
s.Show(p);
cout << "-----" << endl;
s.Show(m);
cout << "-----------" << endl;
stack <int> s1;
s1.push(21);
s1.push(22);
s1.push(23);
s1.push(24);
s1.push(25);
s.Show(s1);
cout << "-----------" << endl;
queue<int> q;
q.push(31);
q.push(32);
q.push(33);
q.push(34);
s.Show(q);
cout << "-----------" << endl;
set<int>s2;
s2 = {41,42,43,44,45,46,47,48,49};
s.Show(s2);
cout << "-----------" << endl;
}
*迭代器的类型为 Template <type>::iterator name,常用auto直接获取
*队列和栈不能遍历没有迭代器
*pair只能放一个元素没有迭代器
*/
# include <iostream>
# include <vector>
# include <list>
# include <map>
# include <stack>
# include <queue>
# include <set>
using namespace std;
class STL {
public:
//查看动态数组
void Show(vector<int> s) {
for (auto it = s.begin(); it != s.end(); it++){
cout << *it << " ";
}
cout << endl;
}
//查看链表
void Show(list<int> s) {
for (auto it = s.begin(); it != s.end(); it++){
cout << *it << " ";
}
cout << endl;
}
//查看映射
void Show(map<int , char> s) {
for (auto it = s.begin(); it != s.end(); it++){
cout << it->first << " : " << it->second << endl;
}
}
//查看集合
void Show(set<int> s){
for (auto it = s.begin(); it != s.end(); it++){
cout << *it << " ";
}
cout << endl;
}
//查看pair
void Show(pair<int , char> s) {
cout << s.first << " : " << s.second << endl;
}
//查看队列
void Show(queue<int> s){
cout << "队首 : " << s.front() << endl;
cout << "队尾 : " << s.back() << endl;
}
//查看栈
void Show(stack<int> s) {
cout <<"栈顶 : " << s.top()<< endl;
}
};
int main()
{
STL s;
vector<int> v;
v.push_back(3);
v.push_back(4);
v.push_back(5);
v.push_back(6);
s.Show(v);
cout << "-----------" << endl;
list <int> l;
l.push_back(15);
l.push_front(14);
l.push_front(13);
l.push_back(16);
s.Show(l);
cout << "-----------" << endl;
map<int , char> m;
m.insert({1,'a'});
m.insert({2,'b'});
m.insert({3,'c'});
m.insert({4,'d'});
s.Show(m);
cout << "-----------" << endl;
pair<int,char> p;
p = make_pair(5,'e');
m.insert(p);
s.Show(p);
cout << "-----" << endl;
s.Show(m);
cout << "-----------" << endl;
stack <int> s1;
s1.push(21);
s1.push(22);
s1.push(23);
s1.push(24);
s1.push(25);
s.Show(s1);
cout << "-----------" << endl;
queue<int> q;
q.push(31);
q.push(32);
q.push(33);
q.push(34);
s.Show(q);
cout << "-----------" << endl;
set<int>s2;
s2 = {41,42,43,44,45,46,47,48,49};
s.Show(s2);
cout << "-----------" << endl;
}