-
Notifications
You must be signed in to change notification settings - Fork 0
/
Stack.h
executable file
·51 lines (43 loc) · 1.46 KB
/
Stack.h
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
#pragma once
#ifndef STACK_H
#define STACK_H
#include "Deque.h"
#include "Iterator1.h"
#include "TypeTraits.h"
#include "TypeTraits.h"
namespace My_STL {
template<class T,class Sequence=deque<T>>
class stack;
template<class T,class Sequence>
bool operator==(const stack<T,Sequence>&,const stack<T,Sequence>&);
template<class T,class Sequence>
bool operator<(const stack<T,Sequence>&,const stack<T,Sequence>&);
template<class T,class Sequence>
class stack {
friend bool operator==<T,Sequence>(const stack<T,Sequence>&,const stack<T,Sequence>&);
friend bool operator< <T,Sequence>(const stack<T,Sequence>&,const stack<T,Sequence>&);
public:
typedef typename Sequence::value_type value_type;
typedef typename Sequence::size_type size_type;
typedef typename Sequence::reference reference;
typedef typename Sequence::const_reference const_reference;
protected:
Sequence c;
public:
bool empty()const { return c.empty(); }
size_type size()const { return c.size(); }
reference top() { return c.back(); }
const_reference top()const { return c.back(); }
void push(const value_type &x) { c.push_back(x); }
void pop() { c.pop_back(); }
};
template<class T,class Sequence>
bool operator==(const stack<T,Sequence> &lhs,const stack<T,Sequence> &rhs){
return lhs.c==rhs.c;
}
template<class T,class Sequence>
bool operator<(const stack<T,Sequence> &x,const stack<T,Sequence> &y){
return x.c<y.c;
}
}
#endif