Implement a stack

This commit is contained in:
Baptiste Wicht 2014-01-29 20:59:39 +01:00
parent 86dc1b2e9a
commit d0567e166e

View File

@ -0,0 +1,49 @@
//=======================================================================
// Copyright Baptiste Wicht 2013-2014.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//=======================================================================
#ifndef STL_STACK_H
#define STL_STACK_H
#include "stl/vector.hpp"
#include "stl/types.hpp"
namespace std {
template<typename T, typename C = std::vector<T>>
struct stack {
private:
C container;
public:
bool empty() const {
return size() == 0;
}
size_t size() const {
return container.size();
}
void push(const T& value){
container.push_back(value);
}
void pop(){
container.pop_back();
}
T& top(){
return container.back();
}
const T& top() const {
return container.back();
}
};
} //end of namespace std
#endif