1. 栈用数组怎么实现
#define MAXSIZE 10;
template<class T>
class Stack {
public: //默认构造函数
Stack();
Stack(size_t maxElements);
Stack(T data[],size_t maxElments);
~Stack() {
delete[] arrays;
}
//入栈
void Push(T data) {
if(isFull())
throw runtime_error("Full stack");
else {
top++;//指向栈顶
arrays[top]=data;
}
}
//出栈并返回
T Pop(){
if(isEmpty())
throw runtime_error("No elements in the stack");
else {
T data=arrays[top];
top--;
return data;
}
}
//返回栈顶元素
T T