首页 > 编程语言 > 详细

c++堆栈实现

时间:2014-05-26 17:10:30      阅读:276      评论:0      收藏:0      [点我收藏+]

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++堆栈实现

原文:http://www.cnblogs.com/oversea201405/p/3752737.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!