array
#include <array>
#include <iostream>
using namespace std;
int main()
{
array<int, 5> a = {1, 2, 3, 4, 5};
array<int, 3 > b;
array<int, 3> c = {10,20};
array<int, 3> d = c;
cout << a.size() << a.max_size() << endl;
for (array<int, 5>::iterator i = a.begin(); i != a.end();i++)
cout << *i;
cout << endl
<< a.at(3) << a.back() << a.data() << endl;
b.swap(c);
c.fill(3);
cout << (c < b) << (c != b) << endl;
cout << get<2>(a) << endl;
get<2>(a) = get<4>(a);
a[1] = 0;
return 0;
}
vector
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
bool Comp(const int &a,const int &b)
{
return a>b;
}
int main()
{
vector<int> a;
vector<int> b{1, 2, 3};
vector<int> vec={3,2,4,5,4,1,6};
vector<int> c(vec.begin()+1,vec.end());
vector<int> d(7);
vector<int> e(vec);
vector<int> f(7,3);
vec.push_back(1);
vec.insert(vec.begin() + 1, 9);
vec.insert(vec.begin(), {1, 2, 3});
vec.insert(vec.begin(), b.begin(), b.end());
vec.emplace(vec.begin(), 2);
vec.emplace_back (100);
vec.erase(vec.begin()+2);
vec.erase(vec.begin()+2,vec.begin()+3);
vec.pop_back();
vector<int>::iterator it;
for(it=vec.begin();it!=vec.end();it++)
cout<<*it<<endl;
a.clear();
a.empty();
vec.size();
vec.at(2);
vec.front();
vec.back();
a.assign(7, 3);
a.assign(vec.begin(), vec.begin()+2);
int k[3]{1, 2, 3};
a.assign(k, k + 1);
reverse(a.begin(),a.end());
sort(vec.begin(),vec.end()-1);
sort(vec.begin(), vec.end(), Comp);
a.reserve(10);
vector<int>().swap(vec);
vector<int> tmp = vec;
vec.swap(tmp);
vec.max_size();
vec.rbegin();
vec.rend();
vec.resize(5);
vec.resize(8, 10);
vec.data();
return 0;
}
list
#include <list>
#include <iostream>
using namespace std;
int main()
{
list<int> a;
list<int> b(5,4);
list<int> c(b);
list<int> d = c;
list<int> e(3);
list<int> f(b.begin(), b.end());
b.push_back(6);
b.push_front(9);
b.insert(b.begin(), 3);
b.insert(b.begin(), 3, 20);
b.insert(b.end(), c.begin(), c.end());
b.splice(++b.begin(), e);
e.splice(e.begin(), b, b.begin());
e.splice(e.begin(), b, b.begin()), b.end();
b.empty();
b.resize(5);
b.resize(10, 9);
b.front();
b.back();
e.assign(4, 5);
e.assign(b.begin(), b.end());
b.reverse();
b.swap(a);
swap(a, b);
c.clear();
b.pop_back();
b.pop_front();
b.erase(b.begin());
b.erase(b.begin(), b.end());
b.remove(9);
b.unique();
b.merge(e, greater<int>());
b.sort();
return 0;
}
stack
#include <iostream>
#include <stack>
#include <deque>
#include <vector>
using namespace std;
int main()
{
deque<int> mydeque (3,100);
vector<int> myvector (2,200);
stack<int> a;
stack<int> b (mydeque);
stack<int,std::vector<int> > c;
stack<int,std::vector<int> > d(myvector);
cout << b.top() << endl;
b.pop();
b.push(1);
b.emplace(5);
cout << b.size();
cout << b.empty();
c.swap(d);
return 0;
}
queue
#include <iostream>
#include <queue>
#include <list>
#include <vector>
using namespace std;
int main()
{
deque<int> mydeck (3,100);
list<int> mylist (2,200);
queue<int> a;
queue<int> b(a);
queue<int, list<int>> c;
queue<int> d(mydeck);
queue<int, list<int> > e (mylist);
cout << d.back()
<< d.front()
<< d.empty()
<< d.size() << endl;
d.pop();
d.push(2);
b.swap(a);
b.emplace(2);
priority_queue <int,vector<int>,greater<int> > q;
priority_queue <int,vector<int>,less<int> > p;
return 0;
}
deque
#include <iostream>
#include <deque>
using namespace std;
int main()
{
deque<int> a{1,2,3,4};
deque<int> b(3, 4);
deque<int> c(b.begin(), b.end()-1);
deque<int> d(b);
a.assign(b.begin(), b.end());
a.assign(4, 6);
a = b;
a.swap(b);
a.empty();
a.size();
a.resize(5);
a.resize(6, 3);
a.push_back(4);
a.push_front(5);
a.pop_back();
a.pop_front();
a.erase(a.begin());
a.erase(a.begin(), a.begin()+1);
b.clear();
a.insert(a.begin(), 3);
a.insert(a.begin(), 3, 4);
a.insert(a.begin(), b.begin(), b.end());
a.emplace(a.begin(), 6);
a.emplace_front(7);
a.emplace_back(9);
a.at(0);
a.front();
a.back();
return 0;
}