{"id":25594100,"url":"https://github.com/sahilll94/standard-template-library-in-cpp","last_synced_at":"2025-04-13T00:05:43.157Z","repository":{"id":269300746,"uuid":"906997775","full_name":"Sahilll94/Standard-Template-Library-in-CPP","owner":"Sahilll94","description":"A repository where the operation and how does the containers in  C++ rich library Standard Template Library (STL) works.","archived":false,"fork":false,"pushed_at":"2025-01-22T14:50:20.000Z","size":323,"stargazers_count":4,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-13T00:05:28.143Z","etag":null,"topics":["cpp","stl","stl-algorithms","stl-containers"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Sahilll94.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-22T14:28:39.000Z","updated_at":"2025-01-22T14:51:00.000Z","dependencies_parsed_at":null,"dependency_job_id":"bafae517-33a7-4549-ab20-f6a6d6f659c2","html_url":"https://github.com/Sahilll94/Standard-Template-Library-in-CPP","commit_stats":null,"previous_names":["sahilll94/standard-template-library-in-cpp"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sahilll94%2FStandard-Template-Library-in-CPP","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sahilll94%2FStandard-Template-Library-in-CPP/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sahilll94%2FStandard-Template-Library-in-CPP/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sahilll94%2FStandard-Template-Library-in-CPP/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Sahilll94","download_url":"https://codeload.github.com/Sahilll94/Standard-Template-Library-in-CPP/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248647302,"owners_count":21139086,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp","stl","stl-algorithms","stl-containers"],"created_at":"2025-02-21T10:32:50.767Z","updated_at":"2025-04-13T00:05:43.133Z","avatar_url":"https://github.com/Sahilll94.png","language":"C++","readme":"# Standard Template Library in C++\r\n\r\nWelcome to the **Standard Template Library in C++** repository! This repository provides an in-depth exploration of the containers in the C++ Standard Template Library (STL), demonstrating how each container works, its operations, and performance characteristics. Whether you are a beginner looking to understand the basics of STL or an advanced user seeking optimization tips, this repository has got you covered.\r\n\r\n## Table of Contents\r\n\r\n- [Overview](#overview)\r\n- [Containers Covered](#containers-covered)\r\n- [Operations](#operations)\r\n- [Examples](#examples)\r\n- [Usage](#usage)\r\n- [Contributing](#contributing)\r\n- [License](#license)\r\n- [STL Sets and Maps Guide](#stl-sets-and-maps-guide)\r\n\r\n## Overview\r\n\r\nThe **Standard Template Library (STL)** in C++ is a collection of template classes and functions that implement common data structures and algorithms. STL includes several powerful containers, such as vectors, maps, sets, lists, and queues, each designed to handle different types of data manipulation efficiently.\r\n\r\nThis repository serves as a guide to understanding how these containers function, how to use them, and the performance trade-offs of each. Through well-documented examples and explanations, you can explore the core features of each container.\r\n\r\n## Containers Covered\r\n\r\nThe following STL containers are explored in this repository:\r\n\r\n1. **Vector**\r\n   - Dynamic array, which allows random access and supports efficient resizing.\r\n2. **List**\r\n   - Doubly linked list, optimized for insertions and deletions at both ends.\r\n3. **Deque**\r\n   - Double-ended queue that allows fast insertions and deletions at both ends.\r\n4. **Set**\r\n   - Collection of unique elements with automatic sorting.\r\n5. **Map**\r\n   - Key-value pairs where each key is unique, and values are associated with keys.\r\n6. **Queue**\r\n   - FIFO (First In First Out) data structure.\r\n7. **Stack**\r\n   - LIFO (Last In First Out) data structure.\r\n8. **Priority Queue**\r\n   - Specialized queue that allows access to the highest priority element.\r\n\r\nEach container includes a breakdown of:\r\n- Basic operations (insert, delete, access)\r\n- Time complexities of each operation\r\n- Real-world use cases and performance considerations\r\n\r\n## Operations\r\n\r\nHere are some common operations demonstrated for each container:\r\n\r\n- **Insertion**\r\n- **Deletion**\r\n- **Traversal**\r\n- **Search**\r\n- **Modification**\r\n- **Sorting (where applicable)**\r\n\r\nThese operations are explained with code examples and their time complexities are discussed.\r\n\r\n## Examples\r\n\r\nEach container comes with a set of examples that show how to use it in real-world scenarios. Here’s a brief example for a **Vector**:\r\n\r\n### Vector Example:\r\n\r\n```cpp\r\n#include \u003ciostream\u003e\r\n#include \u003cvector\u003e\r\n\r\nint main() {\r\n    std::vector\u003cint\u003e vec;\r\n\r\n    // Inserting elements\r\n    vec.push_back(10);\r\n    vec.push_back(20);\r\n    vec.push_back(30);\r\n\r\n    // Accessing elements\r\n    std::cout \u003c\u003c \"First element: \" \u003c\u003c vec[0] \u003c\u003c std::endl;\r\n\r\n    // Traversing the vector\r\n    for (int i = 0; i \u003c vec.size(); ++i) {\r\n        std::cout \u003c\u003c \"Element \" \u003c\u003c i \u003c\u003c \": \" \u003c\u003c vec[i] \u003c\u003c std::endl;\r\n    }\r\n\r\n    // Deleting an element\r\n    vec.pop_back();\r\n    std::cout \u003c\u003c \"After pop_back, size: \" \u003c\u003c vec.size() \u003c\u003c std::endl;\r\n\r\n    return 0;\r\n}\r\n```\r\n\r\n# STL Sets and Maps Guide\r\n\r\n## Sets in C++\r\n\r\n```\r\n┌─────────────────────────────────────────────┐\r\n│                    SETS                     │\r\n├───────────────┬────────────┬───────────────┤\r\n│     SET       │  MULTISET  │ UNORDERED_SET │\r\n├───────────────┼────────────┼───────────────┤\r\n│ [2,3,4,5]     │[2,2,3,3,4] │ [5,2,4,3]     │\r\n│               │            │               │\r\n│ ✓ Unique     │ × Not      │ ✓ Unique     │\r\n│ ✓ Sorted     │   Unique   │ × Not        │\r\n│              │ ✓ Sorted   │   Sorted     │\r\n└───────────────┴────────────┴───────────────┘\r\n```\r\n\r\n## Maps in C++\r\n\r\n```\r\n┌─────────────────────────────────────────────┐\r\n│                    MAPS                     │\r\n├───────────────┬────────────┬───────────────┤\r\n│     MAP       │  MULTIMAP  │ UNORDERED_MAP │\r\n├───────────────┼────────────┼───────────────┤\r\n│{1:\"A\",2:\"B\"}  │{1:\"A\",     │ {2:\"B\",       │\r\n│               │ 1:\"B\",     │  1:\"A\",       │\r\n│               │ 2:\"C\"}     │  4:\"D\"}       │\r\n│ ✓ Unique Keys │ × Multiple │ ✓ Unique Keys │\r\n│ ✓ Sorted Keys │   Keys     │ × Not        │\r\n│               │ ✓ Sorted   │   Sorted     │\r\n└───────────────┴────────────┴───────────────┘\r\n```\r\n\r\n### Time Complexities\r\n\r\n#### Sets\r\n- Set: O(log n) for insertion/deletion\r\n- Multiset: O(log n) for insertion/deletion\r\n- Unordered_set: O(1) average, O(n) worst case\r\n\r\n#### Maps\r\n- Map: O(log n) for insertion/deletion\r\n- Multimap: O(log n) for insertion/deletion\r\n- Unordered_map: O(1) average, O(n) worst case\r\n\r\n\r\n## Usage\r\n\r\nTo explore the code:\r\n\r\n1. Clone this repository:\r\n    ```bash\r\n    git clone https://github.com/yourusername/Standard-Template-Library-in-CPP.git\r\n    ```\r\n\r\n2. Navigate into the project directory:\r\n    ```bash\r\n    cd Standard-Template-Library-in-CPP\r\n    ```\r\n\r\n3. Compile and run the example files using your favorite C++ compiler:\r\n    ```bash\r\n    g++ -o vector_example vector_example.cpp\r\n    ./vector_example\r\n    ```\r\n\r\nFeel free to modify the examples to explore different operations or containers.\r\n\r\n## Contributing\r\n\r\nContributions are welcome! If you find any issues or have improvements or suggestions for the repository, please feel free to fork the repository and submit a pull request.\r\n\r\n### How to Contribute:\r\n\r\n1. Fork the repository.\r\n2. Create a new branch (`git checkout -b feature-branch`).\r\n3. Make your changes.\r\n4. Commit your changes (`git commit -am 'Add new feature'`).\r\n5. Push to your branch (`git push origin feature-branch`).\r\n6. Open a pull request.\r\n\r\n## License\r\n\r\nThis repository is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\r\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsahilll94%2Fstandard-template-library-in-cpp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsahilll94%2Fstandard-template-library-in-cpp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsahilll94%2Fstandard-template-library-in-cpp/lists"}