class MyCircularDeque {
public:
list<int>obj;
int size=0;
int capacity;
MyCircularDeque(int k) {
this->capacity=k;
}
bool insertFront(int value) {
if(this->capacity==obj.size())
{
return false;
}
obj.push_front(value);
size++;
return true;
}
bool insertLast(int value) {
if(this->capacity==obj.size())
{
return false;
}
obj.push_back(value);
size++;
return true;
}
bool deleteFront() {
if(obj.size()>0)
{
obj.pop_front();
size--;
return true;
}
return false;
}
bool deleteLast() {
if(obj.size()>0)
{
obj.pop_back();
size--;
return true;
}
return false;
}
int getFront() {
if(obj.size()==0)
{
return -1;
}
return obj.front();
}
int getRear() {
if(obj.size()==0)
{
return -1;
}
return obj.back();
}
bool isEmpty() {
return obj.size()==0;
}
bool isFull() {
return obj.size()==capacity;
}
};
转载请注明原文地址:https://ipadbbs.8miu.com/read-23069.html