forked from ciberst/MP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Stack.cpp
60 lines (57 loc) · 908 Bytes
/
Stack.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//Александр Жиров, KKC-1-12
//stack
#include <iostream>
#include <vector>
//stack.h
template<typename T,typename container=std::vector<int>>
class my_stack
{
private:
container c;
public:
void push(const T& x)
{
c.push_back(x);
}
void pop()
{
c.pop_back();
}
bool empty()
{
return c.empty();
}
size_t size()
{
return c.size();
}
T& top()
{
return c.back();
}
void swap(my_stack &x)
{
c.swap(x.c);
}
};
using namespace std;
int main()
{
my_stack<int> a,b;
for(int i=1;i!=10;a.push(i++));
for(int i=0;i!=9;i++)
{
cout<<a.top();
a.pop();
}
for(int i=9;i!=0;a.push(i--));
b.swap(a);
cout<<endl<<b.empty()<<endl;
while(!b.empty())
{
cout<<b.top();
b.pop();
}
std::vector<int> c;
return 0;
}