일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
Tags
- 수학
- pandas
- float
- react
- c
- 반응형 웹
- 알고리즘
- 포토샵
- Gap
- SK바이오사이언스
- grid
- transform
- spring
- stl
- 미디어 쿼리
- Javascript
- REM
- box-sizing
- Photoshop
- 확률
- 강화학습
- Prefix Sums
- c++
- CSS
- 소수
- 상태
- skt membership
- 백준
- Codility
- 통신사할인
Archives
- Today
- Total
sliver__
[Mastering C++ Programming] - Deque 본문
728x90
- Deque는 Double ended queue 이며 dynamic array 또는 vector로 구현되어있다.
- O(1)에 front, back에 input이 가능하다.
- deque는 real location에 영향을 받지 않는다.
#include <iostream>
#include <deque>
#include <algorithm>
#include <iterator>
using namespace std;
int main () {
deque<int> d = { 10, 20, 30, 40, 50 };
cout << "\nInitial size of deque is " << d.size() << endl;
d.push_back( 60 );
d.push_front( 5 );
cout << "\nSize of deque after push back and front is " << d.size() << endl;
copy ( d.begin(), d.end(), ostream_iterator<int>( cout, "\t" ) );
d.clear();
cout << "\nSize of deque after clearing all values is " << d.size() <<
endl;
cout << "\nIs the deque empty after clearing values ? " << ( d.empty()
? "true" : "false" ) << endl;
return 0;
}
- 결과는 아래와 같다.
./a.out
Initial size of deque is 5
Size of deque after push back and front is 7
5 10 20 30 40 50 60
Size of deque after clearing all values is 0
Is the deque empty after clearing values ? true
728x90
'CS > C++' 카테고리의 다른 글
[Mastering C++ Programming] - Queue (0) | 2022.12.05 |
---|---|
[Mastering C++ Programming] - Stack (0) | 2022.12.05 |
[Mastering C++ Programming] - forward_list (0) | 2022.12.04 |
[Mastering C++ Programming] - List (0) | 2022.12.04 |
[Mastering C++ Programming] - Vector (0) | 2022.12.04 |
Comments