@@ -26,9 +26,9 @@ namespace Algorithm {
26
26
bool Reallocation ();
27
27
bool IsCapacityEnough ()const ;
28
28
29
- T* mStack ;
30
- int mCount ;
31
- int mCapacity ;
29
+ T* m_stack ;
30
+ int m_count ;
31
+ int m_capacity ;
32
32
};
33
33
34
34
// -------------------define
@@ -40,9 +40,9 @@ namespace Algorithm {
40
40
inline Stack<T>::Stack()
41
41
{
42
42
43
- mCount = 0 ;
44
- mCapacity = 0 ;
45
- mStack = nullptr ;
43
+ m_count = 0 ;
44
+ m_capacity = 0 ;
45
+ m_stack = nullptr ;
46
46
47
47
Initialize (DEFAULTCapacity);
48
48
}
@@ -61,66 +61,63 @@ namespace Algorithm {
61
61
Reallocation ();
62
62
}
63
63
64
- mStack [ mCount ] = value;
64
+ m_stack[m_count ] = value;
65
65
66
- mCount ++;
66
+ m_count ++;
67
67
68
68
}
69
69
70
70
template <typename T>
71
71
inline T Stack<T>::Pop()
72
72
{
73
- if (mCount <= 0 )
74
- {
75
- return nullptr ;
76
- }
73
+ assert (m_count > 0 );
77
74
78
- T t = mStack [ mCount - 1 ];
75
+ T t = m_stack[m_count - 1 ];
79
76
80
- mCount --;
77
+ m_count --;
81
78
82
79
return t;
83
80
}
84
81
85
82
template <typename T>
86
83
inline void Stack<T>::Clear()
87
84
{
88
- if (mStack != nullptr )
85
+ if (m_stack != nullptr )
89
86
{
90
- for (int i = 0 ; i < mCount ; i++)
91
- {
92
- mStack [i] = nullptr ;
93
- }
94
-
95
- delete mStack ;
96
- mStack = nullptr ;
97
- mCount = 0 ;
87
+ // for (int i = 0; i < m_count ; i++)
88
+ // {
89
+ // m_stack [i] = nullptr;
90
+ // }
91
+
92
+ delete m_stack ;
93
+ m_stack = nullptr ;
94
+ m_count = 0 ;
98
95
}
99
96
}
100
97
101
98
template <typename T>
102
99
inline int Stack<T>::Count() const
103
100
{
104
- return mCount ;
101
+ return m_count ;
105
102
}
106
103
107
104
template <typename T>
108
105
inline int Stack<T>::Capacity() const
109
106
{
110
- return mCapacity ;
107
+ return m_capacity ;
111
108
}
112
109
113
110
template <typename T>
114
111
inline T& Stack<T>::operator [](int index)
115
112
{
116
- return const_cast <T&>(const_cast <const Stack<T>*>( this )[index ]);
113
+ return const_cast <T&>(static_cast <const Stack<T>&>(* this )[index ]);
117
114
}
118
115
119
116
template <typename T>
120
117
inline const T& Stack<T>::operator [](int index) const
121
118
{
122
119
assert (index >= 0 && index < m_count);
123
- return m_content [index ];
120
+ return m_stack [index ];
124
121
}
125
122
126
123
template <typename T>
@@ -131,43 +128,43 @@ namespace Algorithm {
131
128
return false ;
132
129
}
133
130
134
- mCapacity = size;
131
+ m_capacity = size;
135
132
136
- mCount = 0 ;
133
+ m_count = 0 ;
137
134
138
- mStack = new T[mCapacity ];
135
+ m_stack = new T[m_capacity ];
139
136
140
137
return true ;
141
138
}
142
139
143
140
template <typename T>
144
141
inline bool Stack<T>::Reallocation()
145
142
{
146
- if (mCapacity == 0 )
143
+ if (m_capacity == 0 )
147
144
{
148
145
return false ;
149
146
}
150
147
151
- mCapacity = 2 * mCapacity ;
148
+ m_capacity = 2 * m_capacity ;
152
149
153
- T* newContent = new T[mCapacity ];
150
+ T* newContent = new T[m_capacity ];
154
151
155
- for (int i = 0 ; i < mCount ; i++)
152
+ for (int i = 0 ; i < m_count ; i++)
156
153
{
157
- newContent[i] = mStack [i];
154
+ newContent[i] = m_stack [i];
158
155
}
159
156
160
- delete[] mStack ;
157
+ delete[] m_stack ;
161
158
162
- mStack = newContent;
159
+ m_stack = newContent;
163
160
164
161
return true ;
165
162
}
166
163
167
164
template <typename T>
168
165
inline bool Stack<T>::IsCapacityEnough() const
169
166
{
170
- return mCount < mCapacity ;
167
+ return m_count < m_capacity ;
171
168
}
172
169
173
170
}
0 commit comments