A Stack is a data-structure that
You can only add an element to the top
of the Stack, and
You can only read or remove an element also from the
top.
Please use a vector to implement a Stack
EXAMPLE INPUT
1 2 3 4 5 6 7 8 9EXAMPLE OUTPUT
9 8 7 6 5 4 3 2 1
主程序
#include <vector>
using namespace std;
class
EmptyStackException {};
template <typename E>
class Stack
{
private:
vector<E> elements;
public:
void addFirst(const E & elem);
E removeFirst();
};
#include "source"
#include <iostream>
using
namespace std;
代写
int main() {
Stack<int> stack;
for (int i = 0; i < 9; ++ i) {
int value;
cin
>> value;
stack.addFirst(value);
}
for (int
i = 0; i < 9; ++ i) {
cout << stack.removeFirst() <<
" ";
}
}
原文地址:http://www.cnblogs.com/oversea201405/p/3752737.html