// 坏境 win7 x64 vs2012
#include <iostream>
#include <cassert>
using namespace std;
template <typename T>
class Stack
{
public:
// 构造函数
explicit Stack(const size_t capacity = 10)
:_size(0)
,_capacity(10)
{
// 最小分配10个 大于10 则分配用户指定的大小
_capacity = (_capacity > capacity)? _capacity : capacity;
_array = new T[_capacity];
}
// 拷贝构造函数
explicit Stack(const Stack<T>& s)
{
_array = new T[s._capacity];
_capacity = s._capacity;
_size = s._size;
for (size_t idx = 0; idx < _size; ++idx)
{
_array[idx] = s._array[idx];
}
}
// 赋值重载 简洁版本
Stack& operator=(const Stack<T>& s)
{
if (this != &s)
{
Stack temp(s);
std::swap(_array, temp._array);
_size = s._size;
_capacity = s._capacity;
}
return *this;
}
// 获取当前栈顶
T& Top()const
{
assert(!Empty()); // 断言
return _array[_size -1];
}
/