intpopFront(){ int res = -1; if(!f.empty()) { res = f.front(); f.pop_front(); } elseif(!b.empty()) { res = b.front(); b.pop_front(); } balance(); return res; }
intpopMiddle(){ int s = f.size() + b.size(); int res = -1; if(s != 0) { if(s & 1) { if(!b.empty()) { res = b.front(); b.pop_front(); } elseif(!f.empty()) { res = f.back(); b.pop_back(); } } else { if(!f.empty()) { res = f.back(); f.pop_back(); } elseif(!b.empty()) { res = b.front(); b.pop_front(); } } balance(); } return res; }
intpopBack(){ int res = -1; if(!b.empty()) { res = b.back(); b.pop_back(); } elseif(!f.empty()) { res = f.back(); f.pop_back(); } balance(); return res; } };
/** * Your FrontMiddleBackQueue object will be instantiated and called as such: * FrontMiddleBackQueue* obj = new FrontMiddleBackQueue(); * obj->pushFront(val); * obj->pushMiddle(val); * obj->pushBack(val); * int param_4 = obj->popFront(); * int param_5 = obj->popMiddle(); * int param_6 = obj->popBack(); */