Skip to content

Instantly share code, notes, and snippets.

@hjroh0315
Last active January 27, 2022 14:36
Show Gist options
  • Select an option

  • Save hjroh0315/6ad9193649bd2ecb79a78dded673beaf to your computer and use it in GitHub Desktop.

Select an option

Save hjroh0315/6ad9193649bd2ecb79a78dded673beaf to your computer and use it in GitHub Desktop.
투포인터(?) 덱 구현
#include<iostream>
using namespace std;
template<class T>
struct ptrDeque
{
using iterator=T*;
iterator l,r;
ptrDeque():l(new T),r(l){}
void push_back(T a){*r=a;r++;}
void push_front(T a){l--;*l=a;}
void pop_back(){r--; delete r;}
void pop_front(){iterator t=l;l++; delete t;}
T& operator[](size_t s){return *(l+s);}
iterator begin(){return l;}
iterator end(){return r;}
T& front(){return *l;}
T& back(){return *(r-1);}
};
namespace std
{
template<class T>
T* begin(ptrDeque<T>&p){return p.l;}
template<class T>
T* end(ptrDeque<T>&p){return p.r;}
}
int main()
{
ptrDeque<int> deq;
deq.push_back(100);
deq.push_back(200);
deq.push_back(300);
deq.push_back(400);
deq.push_back(500);
deq.push_front(100);
deq.push_front(200);
deq.push_front(300);
deq.push_front(400);
deq.push_front(500);
deq.pop_back();
for(auto i:deq)cout << i << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment