2024-02-21 09:31:34 +08:00
|
|
|
|
/**
|
|
|
|
|
* File: deque.cpp
|
|
|
|
|
* Created Time: 2022-11-25
|
|
|
|
|
* Author: krahets (krahets@163.com)
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "../utils/common.hpp"
|
|
|
|
|
|
|
|
|
|
/* Driver Code */
|
|
|
|
|
int main() {
|
2024-02-23 14:47:33 +08:00
|
|
|
|
/* <20><>ʼ<EFBFBD><CABC>˫<EFBFBD><CBAB><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
2024-02-21 09:31:34 +08:00
|
|
|
|
deque<int> deque;
|
|
|
|
|
|
2024-02-23 14:47:33 +08:00
|
|
|
|
/* Ԫ<><D4AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
2024-02-21 09:31:34 +08:00
|
|
|
|
deque.push_back(2);
|
|
|
|
|
deque.push_back(5);
|
|
|
|
|
deque.push_back(4);
|
|
|
|
|
deque.push_front(3);
|
|
|
|
|
deque.push_front(1);
|
2024-02-23 14:47:33 +08:00
|
|
|
|
cout << "˫<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> deque = ";
|
2024-02-21 09:31:34 +08:00
|
|
|
|
printDeque(deque);
|
2024-02-23 14:47:33 +08:00
|
|
|
|
cout << "<EFBFBD>Ӻ<EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>˫<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> deque = ";
|
|
|
|
|
printDequeFromBack(deque);
|
2024-02-21 09:31:34 +08:00
|
|
|
|
|
2024-02-23 14:47:33 +08:00
|
|
|
|
/* <20><><EFBFBD><EFBFBD>Ԫ<EFBFBD><D4AA> */
|
2024-02-21 09:31:34 +08:00
|
|
|
|
int front = deque.front();
|
2024-02-23 14:47:33 +08:00
|
|
|
|
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԫ<EFBFBD><EFBFBD> front = " << front << endl;
|
2024-02-21 09:31:34 +08:00
|
|
|
|
int back = deque.back();
|
2024-02-23 14:47:33 +08:00
|
|
|
|
cout << "<EFBFBD><EFBFBD>βԪ<EFBFBD><EFBFBD> back = " << back << endl;
|
2024-02-21 09:31:34 +08:00
|
|
|
|
|
2024-02-23 14:47:33 +08:00
|
|
|
|
/* Ԫ<>س<EFBFBD><D8B3><EFBFBD> */
|
2024-02-21 09:31:34 +08:00
|
|
|
|
deque.pop_front();
|
2024-02-23 14:47:33 +08:00
|
|
|
|
cout << "<EFBFBD><EFBFBD><EFBFBD>׳<EFBFBD><EFBFBD><EFBFBD>Ԫ<EFBFBD><EFBFBD> popFront = " << front << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>׳<EFBFBD><EFBFBD>Ӻ<EFBFBD> deque = ";
|
2024-02-21 09:31:34 +08:00
|
|
|
|
printDeque(deque);
|
|
|
|
|
deque.pop_back();
|
2024-02-23 14:47:33 +08:00
|
|
|
|
cout << "<EFBFBD><EFBFBD>β<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԫ<EFBFBD><EFBFBD> popLast = " << back << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>β<EFBFBD><EFBFBD><EFBFBD>Ӻ<EFBFBD> deque = ";
|
2024-02-21 09:31:34 +08:00
|
|
|
|
printDeque(deque);
|
|
|
|
|
|
2024-02-23 14:47:33 +08:00
|
|
|
|
/* <20><>ȡ˫<C8A1><CBAB><EFBFBD><EFBFBD><EFBFBD>еij<D0B5><C4B3><EFBFBD> */
|
2024-02-21 09:31:34 +08:00
|
|
|
|
int size = deque.size();
|
2024-02-23 14:47:33 +08:00
|
|
|
|
cout << "˫<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>г<EFBFBD><EFBFBD><EFBFBD> size = " << size << endl;
|
2024-02-21 09:31:34 +08:00
|
|
|
|
|
2024-02-23 14:47:33 +08:00
|
|
|
|
/* <20>ж<EFBFBD>˫<EFBFBD><CBAB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD>Ϊ<EFBFBD><CEAA> */
|
2024-02-21 09:31:34 +08:00
|
|
|
|
bool empty = deque.empty();
|
2024-02-23 14:47:33 +08:00
|
|
|
|
cout << "˫<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD>Ϊ<EFBFBD><EFBFBD> = " << empty << endl;
|
2024-02-21 09:31:34 +08:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|