-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprac_Stack.h
62 lines (54 loc) · 928 Bytes
/
prac_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
52
53
54
55
56
57
58
59
60
61
62
template <typename T>
class Stack {
public:
explicit Stack( std::size_t capacity );
~Stack();
void Push( const T& data );
void Pop();
inline const T Top() const
{
return mData[ mSP - 1 ];
}
inline std::size_t GetSize() const
{
return mSP;
}
inline std::size_t GetCapacity() const
{
return mCapacity;
}
private:
const std::size_t mCapacity;
T* mData;
int mSP;
};
// 分からないこと
// explicit
// inline
// あとにつくconst
// std::size_t
template <typename T>
Stack<T>::Stack( std::size_t capacity ) :
mCapacity( capacity ),
mData( new T[ capacity ] ),
mSP( 0 );
{
}
template <typename T>
Stack<T>::~Stack()
{
delete [] mData;
}
template <typename T>
void Stack<T>::Push( const T& data )
{
assert( static_cast<std::size_t>( mSP ) < mCapacity );
mData[ mSP ] = data;
mSP++;
}
template <typename T>
void Stack<T>::Pop()
{
assert( mSP > 0 );
mSP--;
}