码迷,mamicode.com
首页 > 编程语言 > 详细

c++堆栈实现

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

标签:c   class   a   int   c++   os   

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

标签:c   class   a   int   c++   os   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!