
本文共 2815 字,大约阅读时间需要 9 分钟。
������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������`main.cpp`������������������������������������������������������������```cpp#include "pch.h"#include#include "stack1.h"
������������std
������������������������������������������������������������������
using namespace std;_space1::stack s;
���������������������������������������0���9���10������������������������
for (int i = 0; i < 10; ++i) { s.push(i);}
���������������������������������������������������������
int ret = s.top();cout << "���������������: " << ret << endl;s.pop();ret = s.top();cout << "���������������: " << ret << endl;
���������������������������������������������������������������������������������������������������������������
if (s.empty()) { cout << "������������������������" << endl;}
���������������������������������������������������������������������������������������
������������������stack1.h
���������������������������������������������������stack
������������������������T
���
templateclass stack {private: vector elems;public: void push(t const& elem); void pop(); t top() const; bool empty() const; stack(); stack(stack const& other); stack & operator=(stack const& other);};
������������������������������vector
������������������������������������������������������������������������������������������������������������������������������������
������������������������������������������������������������������������������������������������������������������������������������
void stack::pop() { if (stack ::empty()) { cout << "���������������������������" << endl; } elems.pop_back();}
������������������������������������������������������������
t stack::top() const { if (stack ::empty()) { cout << "���������������������������������������" << endl; } return elems.back();}
���������������������������������������������������������������
���������������������������������������������������������������������������������������
#include "pch.h"#includeusing namespace std;
������������������������������������������������������
������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
发表评论
最新留言
关于作者
