c++堆栈实现

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() << " ";
}
}

c++堆栈实现,布布扣,bubuko.com

c++堆栈实现

上一篇:Caused by: java.lang.UnsatisfiedLinkError: Couldn't load BaiduMapVOS_v2_1_3: findLibrary returned nu


下一篇:蜗牛—JavaScript学习之鼠标滑过与离开