--- id: cpp-list title: "C++ List" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["std::list", "doubly linked list 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", "list"] raw_sources: ["https://www.w3schools.com/cpp/cpp_list.asp"] applied_in: [] github_commit: "" --- # [[CPP List]] ## ๐ŸŽฏ ํ•œ ์ค„ ํ†ต์ฐฐ (One-line insight) `list` is the STL container that most directly replaces what C programmers had to hand-build with `struct Node { int data; Node* next; }` โ€” a linked list that grows anywhere and adds/removes at both ends cheaply โ€” but in exchange for that flexibility it gives up random-access indexing entirely (no `list[i]`), so choosing between vector and list is choosing between C-array-like index speed versus C-linked-list-like two-ended growth, expressed here as a one-line design decision instead of a whole custom data structure. [S1] ## ๐Ÿง  ํ•ต์‹ฌ ๊ฐœ๋… (Core concepts) - **`list name`** โ€” declared like a vector, e.g. `list cars;`, requires ``. [S1] - **No index access** โ€” unlike vector, elements cannot be retrieved by `[i]` or `.at(i)`; only `.front()` and `.back()` are available. [S1] - **Both-ends growth** โ€” `.push_front()` / `.push_back()` add at the beginning/end; `.pop_front()` / `.pop_back()` remove from the beginning/end โ€” vectors only optimize the "back" side. [S1] - **`.front()` / `.back()` are also mutable** โ€” assigning to `cars.front() = "Opel"` changes the first element directly, since there's no index-based assignment. [S1] - **Looping restriction** โ€” a traditional indexed `for` loop combined with `.size()` does NOT work for lists (no `cars[i]`); only a for-each loop (or, later, an iterator) can traverse a list. [S1] - **`.size()` / `.empty()`** โ€” same semantics as vector. [S1] ## ๐Ÿ“– ์„ธ๋ถ€ ๋‚ด์šฉ (Details) - Declaration with initial values: `list cars = {"Volvo", "BMW", "Ford", "Mazda"};`. [S1] - Add: `cars.push_front("Tesla"); cars.push_back("VW");`. [S1] - Remove: `cars.pop_front(); cars.pop_back();`. [S1] - The page explicitly shows the broken indexed-loop attempt (`for (int i = 0; i < cars.size(); i++) { cout << cars[i]; }`) as something that will NOT compile, then gives the working for-each replacement. [S1] ## โš–๏ธ ๋ชจ์ˆœ ๋ฐ ์—…๋ฐ์ดํŠธ (Contradictions & updates) - **์ธ๋ฑ์Šค ์ ‘๊ทผ ์ž์ฒด๊ฐ€ ์กด์žฌํ•˜์ง€ ์•Š์Œ**: vector๋Š” ๋ฐฐ์—ด์ฒ˜๋Ÿผ ์ธ๋ฑ์Šค ์ ‘๊ทผ์ด ๊ฐ€๋Šฅํ–ˆ์ง€๋งŒ, list๋Š” ์ˆœ์ฐจ ์—ฐ๊ฒฐ ๊ตฌ์กฐ์ด๊ธฐ ๋•Œ๋ฌธ์— ์ธ๋ฑ์Šค ์ ‘๊ทผ ์ž์ฒด๊ฐ€ ์–ธ์–ด ์ฐจ์›์—์„œ ๋ถˆ๊ฐ€๋Šฅํ•˜๋‹ค๋Š” ์ ์ด ์ด๋ฒˆ ์ฑ•ํ„ฐ์—์„œ vector์™€์˜ ํ•ต์‹ฌ ์ฐจ์ด๋กœ ๋ช…์‹œ๋จ. [S1] - **์–‘์ชฝ ๋ ์‚ฝ์ž…/์‚ญ์ œ๊ฐ€ ๋Œ€์นญ์ ์œผ๋กœ ์ง€์›๋จ**: vector๋Š” ๋’ค์ชฝ(push_back/pop_back)์—๋งŒ ์ตœ์ ํ™”๋˜์–ด ์žˆ์—ˆ์ง€๋งŒ, list๋Š” ์•ž/๋’ค ์–‘์ชฝ ๋ชจ๋‘ push_front/pop_front, push_back/pop_back์œผ๋กœ ๋Œ€์นญ์ ์œผ๋กœ ์ง€์›ํ•œ๋‹ค๋Š” ์ ์ด vector์™€ ๋Œ€๋น„๋จ. [S1] ## ๐Ÿ› ๏ธ ์ ์šฉ ์‚ฌ๋ก€ (Applied in summary) ํ˜„์žฌ ๋ฐœ๊ฒฌ๋œ ์‹ค์ œ ์ ์šฉ ์‚ฌ๋ก€๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค โ€” ์ž๋™์ฐจ ์ด๋ฆ„ ๋ฆฌ์ŠคํŠธ์˜ ์–‘ ๋์— ์›์†Œ๋ฅผ ์ถ”๊ฐ€/์‚ญ์ œํ•˜๋Š” ์˜ˆ์ œ๊ฐ€ ์›๋ฌธ์—์„œ ์ œ์‹œ๋จ. [S1] ## ๐Ÿ’ป ์ฝ”๋“œ ํŒจํ„ด (Code patterns) List-specific operations unavailable on vector โ€” both-ends push/pop (C++): ```cpp #include list cars = {"Volvo", "BMW", "Ford", "Mazda"}; cars.push_front("Tesla"); // add at beginning cars.push_back("VW"); // add at end cars.pop_front(); // remove from beginning cars.pop_back(); // remove from end // No index access โ€” must use for-each: for (string car : cars) { cout << car << "\n"; } ``` ## โœ… ๊ฒ€์ฆ ์ƒํƒœ ๋ฐ ์‹ ๋ขฐ๋„ - **์ƒํƒœ:** draft - **๊ฒ€์ฆ ๋‹จ๊ณ„:** conceptual - **์ถœ์ฒ˜ ์‹ ๋ขฐ๋„:** B (W3Schools โ€” widely used educational reference, not a primary standards body) - **์‹ ๋ขฐ ์ ์ˆ˜:** 0.86 - **์ค‘๋ณต ๊ฒ€์‚ฌ ๊ฒฐ๊ณผ:** ์‹ ๊ทœ ์ƒ์„ฑ (New discovery) ## ๐Ÿ”— ์ง€์‹ ๊ทธ๋ž˜ํ”„ (Knowledge Graph) - **์ƒ์œ„/๋ฃจํŠธ:** [[C++ Tutorial]] - **๊ด€๋ จ ๊ฐœ๋…:** [[CPP Vectors]], [[CPP Stacks]], [[CPP Data Structures]], [[C Pointers]] - **์ฐธ์กฐ ๋งฅ๋ฝ:** ๋ฐ์ดํ„ฐ ๊ตฌ์กฐ(STL) ์„น์…˜ โ€” Stacks ์ฑ•ํ„ฐ๋กœ ์ด์–ด์ง. ## ๐Ÿ“š ์ถœ์ฒ˜ (Sources) - [S1] W3Schools โ€” C++ List โ€” https://www.w3schools.com/cpp/cpp_list.asp ## ๐Ÿ“ ๋ณ€๊ฒฝ ์ด๋ ฅ (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "C++ List" page (Astra wiki-curation, P-Reinforce v3.1 format).