#include <iostream>
#include <vector>
using namespace std;
template <typename elemtype>
class set_stack {
private:
elemtype *elem;
int top_p;
int max_size;
public:
bool is_empty() const { return top_p == -1; }
void push(const elemtype &x) {
elem[++top_p] = x;
}
elemtype pop() {
return elem[--top_p];
}
elemtype top() const {
return elem[top_p];
}
set_stack() {
elem = new elemtype[100];
max_size = 100;
top_p = -1;
}
};
int main()
{
//set_stack<int> ss = set_stack<int>();
set_stack<int> ss;
for (int i = 1; i <= 9; i++) {
ss.push(i*10);
}
while (!ss.is_empty()) {
int top = ss.top();
cout << top << endl;
ss.pop();
}
}
栈的实现(C++)
最新推荐文章于 2024-09-30 18:37:43 发布