--- id: cpp-deque title: "C++ Deque" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["std::deque", "double-ended queue C++", "C++ 데크"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.86 created_at: 2026-07-04 updated_at: 2026-07-04 review_reason: "" merge_history: [] tags: ["cpp", "programming-language", "w3schools", "stl", "deque"] raw_sources: ["https://www.w3schools.com/cpp/cpp_deque.asp"] applied_in: [] github_commit: "" --- # [[CPP Deque]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) `deque` is what queue "should have been" if index access mattered β€” it takes queue's both-ends-conceptual-flexibility one step further by ALSO allowing `[]`/`.at()` indexing like vector, meaning deque is effectively "vector + list's both-ends growth combined," and its existence exposes that the earlier stack/queue restrictions (no brace-init, single/dual access points) were deliberate design trade-offs rather than technical limitations of the "add/remove from ends" idea itself. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **Deque = double-ended queue** β€” unlike a plain queue (front removal, back insertion only), a deque allows adding AND removing from BOTH ends. [S1] - **Index access restored** β€” unlike stack/queue/list, a deque supports `[]` and `.at()` just like vector, combining both-ends flexibility with random access. [S1] - **Brace-initialization allowed** β€” unlike stack/queue, `deque cars = {"Volvo", "BMW", "Ford", "Mazda"};` works directly, matching vector/list syntax. [S1] - **`.push_front()` / `.push_back()`, `.pop_front()` / `.pop_back()`** β€” identical method names to `list`, giving deque list's symmetric growth PLUS vector's indexing. [S1] - **`.front()` / `.back()`, `.size()` / `.empty()`** β€” same as every other sequence container covered so far. [S1] - **Looping** β€” both indexed `for` + `.size()` and for-each work, exactly like vector (unlike list, which only supports for-each). [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) - Access: `cars[0]`, `cars.front()`, `cars.back()`, `cars.at(1)` β€” same safety trade-off as vector (`.at()` throws on out-of-range, `[]` does not). [S1] - Add/remove at both ends: `cars.push_front("Tesla"); cars.push_back("VW"); cars.pop_front(); cars.pop_back();`. [S1] - Both loop styles supported: indexed `for (int i = 0; i < cars.size(); i++)` AND for-each `for (string car : cars)`. [S1] ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) - **stack/queue의 μ œμ•½μ΄ dequeμ—λŠ” μ μš©λ˜μ§€ μ•ŠμŒ**: stackκ³Ό queueλŠ” μ„ μ–Έ μ‹œ μ€‘κ΄„ν˜Έ μ΄ˆκΈ°ν™”κ°€ λΆˆκ°€λŠ₯ν–ˆμ§€λ§Œ, dequeλŠ” vector/list와 λ™μΌν•˜κ²Œ `= {...}`둜 μ¦‰μ‹œ μ΄ˆκΈ°ν™”κ°€ κ°€λŠ₯ν•˜λ‹€λŠ” 점이 이번 μ±•ν„°μ—μ„œ 확인됨 β€” μ•žμ„œμ˜ μ œμ•½μ΄ "μ–‘ 끝 μ‚½μž…/μ‚­μ œ μ»¨ν…Œμ΄λ„ˆμ˜ 본질"이 μ•„λ‹ˆλΌ 섀계 μ„ νƒμ΄μ—ˆμŒμ„ λ³΄μ—¬μ€Œ. [S1] - **인덱슀 μ ‘κ·Όκ³Ό μ–‘μͺ½ 끝 μ„±μž₯이 λ™μ‹œμ— κ°€λŠ₯해짐**: listλŠ” μ–‘μͺ½ 끝 μ„±μž₯은 κ°€λŠ₯ν–ˆμ§€λ§Œ 인덱슀 접근이 λΆˆκ°€λŠ₯ν–ˆκ³ , queue/stack은 인덱슀 접근도 μ–‘μͺ½ 끝 μž„μ˜ 접근도 μ•ˆ λμ§€λ§Œ, dequeλŠ” 이 λ‘˜μ„ λͺ¨λ‘ κ°–μΆ˜ μ»¨ν…Œμ΄λ„ˆλ‘œ 확인됨. [S1] ## πŸ› οΈ 적용 사둀 (Applied in summary) ν˜„μž¬ 발견된 μ‹€μ œ 적용 사둀가 μ—†μŠ΅λ‹ˆλ‹€ β€” μžλ™μ°¨ 이름 deque에 인덱슀 μ ‘κ·Ό, μ–‘ 끝 push/pop, 순회λ₯Ό λͺ¨λ‘ μ μš©ν•˜λŠ” μ˜ˆμ œκ°€ μ›λ¬Έμ—μ„œ μ œμ‹œλ¨. [S1] ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) Deque combines vector's indexing with list's both-ends growth (C++): ```cpp #include deque cars = {"Volvo", "BMW", "Ford", "Mazda"}; cout << cars[0]; // indexed access, like vector cars.push_front("Tesla"); // both-ends growth, like list cars.push_back("VW"); cars.pop_front(); cars.pop_back(); for (int i = 0; i < cars.size(); i++) { // indexed loop works too cout << cars[i] << "\n"; } ``` ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.86 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[C++ Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[CPP Queues]], [[CPP Vectors]], [[CPP List]], [[CPP Sets]] - **μ°Έμ‘° λ§₯락:** 데이터 ꡬ쑰(STL) μ„Ήμ…˜ β€” Sets μ±•ν„°λ‘œ 이어짐. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” C++ Deque β€” https://www.w3schools.com/cpp/cpp_deque.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "C++ Deque" page (Astra wiki-curation, P-Reinforce v3.1 format).