stack容器
#include <IOStream>
using namespace std;
#include <stack>//容器头文件
void test()
{
stack<int>p;
p.push(100);
p.push(1000);
p.push(100);
while(!p.empty())
{
cout<<p.top()<<endl;
p.pop();
}
}
int main()
{
test();
system("pause");
return 0;
}
queue容器
#include <iostream>
using namespace std;
#include <stack>//容器头文件
#include <string>
#include <queue>
class person
{
public:
person(string name,int age)
{
this->m_name=name;
this->m_age=age;
}
string m_name;
int m_age;
};
void test()
{
queue<person>q;//队列容器,先进先出
person p1("zhang",15);
person p2("zhan",18);
q.push(p1);
q.push(p2);
while(!q.empty())
{
cout<<q.front().m_age<<q.back().m_name<<endl;
q.pop();
}
}
int main()
{
test();
system("pause");
return 0;
}
for_reach遍历算法
#include <iostream>
using namespace std;
#include <stack>//容器头文件
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <functional>
class fun
{
public:
void operator()(int val)
{
cout<<val<<" "<<endl;
}
};
void test()
{
vector<int>p;
p.push_back(120);
p.push_back(10);
p.push_back(1400);
p.push_back(140);
for_each(p.begin(),p.end(),fun());
}
int main()
{
test();
system("pause");
return 0;
}