Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- #include <string>
- #include <utility>
- #include <vector>
- #include "test_runner.h"
- using namespace std;
- template <typename T> class Deque{
- public:
- Deque(){}
- bool Empty()const{
- if(_back.empty() && _front.empty())
- return true;
- return false;
- }
- size_t Size() const{
- return(_front.size() + _back.size());
- }
- const T& operator[](size_t index) const{
- if(index + 1 > _front.size()){
- return (_back[index - _front.size()]);
- }
- }
- T& operator[]( size_t index){
- if(index + 1 > _front.size()){
- return (_back[index - _front.size()]);
- }
- }
- const T& At(size_t index) const {
- if(index >= _front.size() + _back.size())
- throw out_of_range("deq");
- if(index + 1 > _front.size()){
- return (&_back[index - _front.size()]);
- }
- }
- T& At(size_t index){
- if(index >= _front.size() + _back.size())
- throw out_of_range("deq");
- if(index + 1 > _front.size()){
- return (&_back[index - _front.size()]);
- }
- }
- T& Front() const{
- if(!_front.empty())
- return &_front.front();
- }
- T& Front(){
- if(!_front.empty())
- return &_front.front();
- }
- T& Back() const{
- if(!_back.empty())
- return &_back.back();
- }
- T& Back(){
- if(!_back.empty())
- return &_back.back();
- }
- void PushFront(const T& val){
- _front.push_back(val);
- }
- void PushBack(const T& val){
- _back.push_back(val);
- }
- private:
- vector<T> _front,_back;
- vector<T> v;
- };
- void TestDeque() {
- }
- int main() {
- TestRunner tr;
- RUN_TEST(tr, TestDeque);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement