--- id: cpp-queues title: "C++ Queues" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["std::queue", "FIFO", "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", "queue", "fifo"] raw_sources: ["https://www.w3schools.com/cpp/cpp_queues.asp"] applied_in: [] github_commit: "" --- # [[CPP Queues]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) `queue` is stack's mirror image β€” same restricted-access philosophy (no arbitrary indexing, no brace-list initialization, only `.push()`/`.pop()`), but instead of both ends collapsing onto one "top," a queue keeps `.front()` and `.back()` as two DISTINCT accessible ends, encoding FIFO order (supermarket line: first in line, first served) the same way stack encoded LIFO β€” the two containers share nearly identical method names (`.push()`, `.pop()`, `.size()`, `.empty()`) but differ in exactly which end `.pop()` removes from, which is the single fact that determines whether a container behaves like a stack or a queue. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **FIFO (First In, First Out)** β€” the first element added is the first one removed, unlike stack's LIFO. [S1] - **`queue name`** β€” requires ``; like stack, CANNOT be initialized with a curly-brace list at declaration β€” must use `.push()` after declaring. [S1] - **`.push()`** β€” adds an element to the BACK (end) of the queue. [S1] - **`.front()` / `.back()`** β€” TWO accessible points (unlike stack's single `.top()`): front is the oldest/first element, back is the newest/last element; both are also assignable. [S1] - **`.pop()`** β€” removes the FRONT element (the oldest one) β€” this is the key difference from stack's `.pop()`, which removes from the top/back instead. [S1] - **`.size()` / `.empty()`** β€” same semantics as stack/list/vector. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) - Declaration + fill: `queue cars; cars.push("Volvo"); cars.push("BMW"); cars.push("Ford"); cars.push("Mazda");` β€” resulting order: Volvo(front), BMW, Ford, Mazda(back). [S1] - Access/modify: `cars.front()` β†’ "Volvo", `cars.back()` β†’ "Mazda"; both can be reassigned directly (`cars.front() = "Tesla";`). [S1] - Remove: `cars.pop();` removes Volvo (the front/oldest), making BMW the new front. [S1] - Same brace-initialization restriction as stack is called out explicitly: `queue cars = {"Volvo", ...};` is not allowed. [S1] ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) - **stackκ³Ό λ™μΌν•œ λ©”μ„œλ“œλͺ…, λ°˜λŒ€ λ°©ν–₯ 의미**: stack의 `.pop()`은 top(κ°€μž₯ 졜근 μΆ”κ°€λœ μš”μ†Œ)을 μ œκ±°ν–ˆμ§€λ§Œ, queue의 `.pop()`은 front(κ°€μž₯ 였래된 μš”μ†Œ)λ₯Ό μ œκ±°ν•œλ‹€λŠ” 점이 이번 μ±•ν„°μ—μ„œ stack과의 핡심 λŒ€λΉ„λ‘œ 확인됨 β€” λ©”μ„œλ“œ 이름은 같아도 λ™μž‘ λ°©ν–₯이 μ •λ°˜λŒ€. [S1] - **μ ‘κ·Ό κ°€λŠ₯ 지점이 ν•˜λ‚˜μ—μ„œ λ‘˜λ‘œ λŠ˜μ–΄λ‚¨**: stack은 `.top()` ν•˜λ‚˜λ§Œ λ…ΈμΆœν–ˆμ§€λ§Œ, queueλŠ” `.front()`와 `.back()` 두 지점을 λͺ¨λ‘ λ…ΈμΆœν•œλ‹€λŠ” 점이 FIFO ꡬ쑰의 νŠΉμ„±μƒ ν•„μš”ν•œ 차이둜 확인됨. [S1] ## πŸ› οΈ 적용 사둀 (Applied in summary) ν˜„μž¬ 발견된 μ‹€μ œ 적용 사둀가 μ—†μŠ΅λ‹ˆλ‹€ β€” μŠˆνΌλ§ˆμΌ“ μ€„μ„œκΈ°μ— λΉ„μœ ν•΄ FIFOλ₯Ό μ„€λͺ…ν•˜κ³ , μžλ™μ°¨ 이름을 push()둜 μ±„μš΄ λ’€ front()/back()으둜 ν™•μΈν•˜λŠ” μ˜ˆμ œκ°€ μ›λ¬Έμ—μ„œ μ œμ‹œλ¨. [S1] ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) Queue push/front/back/pop β€” pop always removes from the front, unlike stack (C++): ```cpp #include queue cars; cars.push("Volvo"); cars.push("BMW"); cars.push("Ford"); cars.push("Mazda"); cout << cars.front(); // "Volvo" (oldest) cout << cars.back(); // "Mazda" (newest) cars.pop(); // removes "Volvo" (the front) cout << cars.front(); // now "BMW" ``` ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.86 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[C++ Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[CPP Stacks]], [[CPP Data Structures]], [[CPP Deque]] - **μ°Έμ‘° λ§₯락:** 데이터 ꡬ쑰(STL) μ„Ήμ…˜ β€” Stacks와 짝을 μ΄λ£¨λŠ” 챕터, λ‹€μŒμ€ Deque. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” C++ Queues β€” https://www.w3schools.com/cpp/cpp_queues.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "C++ Queues" page (Astra wiki-curation, P-Reinforce v3.1 format).