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