{"id":20345815,"url":"https://github.com/izzypt/cpp_module_08","last_synced_at":"2026-05-08T11:38:36.682Z","repository":{"id":212135174,"uuid":"730703384","full_name":"izzypt/CPP_Module_08","owner":"izzypt","description":" This module is designed to help you understand templated containers, iterators and algorithms in CPP. ","archived":false,"fork":false,"pushed_at":"2023-12-14T21:34:29.000Z","size":20,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-14T21:46:38.446Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/izzypt.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}},"created_at":"2023-12-12T13:48:40.000Z","updated_at":"2023-12-14T21:10:38.000Z","dependencies_parsed_at":"2023-12-14T23:06:10.618Z","dependency_job_id":null,"html_url":"https://github.com/izzypt/CPP_Module_08","commit_stats":null,"previous_names":["izzypt/cpp_module_08"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izzypt%2FCPP_Module_08","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izzypt%2FCPP_Module_08/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izzypt%2FCPP_Module_08/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izzypt%2FCPP_Module_08/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/izzypt","download_url":"https://codeload.github.com/izzypt/CPP_Module_08/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241876621,"owners_count":20035396,"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":[],"created_at":"2024-11-14T22:09:52.503Z","updated_at":"2026-05-08T11:38:36.618Z","avatar_url":"https://github.com/izzypt.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CPP_Module_08\n This module is designed to help you understand templated containers, iterators and algorithms in CPP. \n\n\n# Table of Content\n\n- [What is STL](#stl)\n- [What are STL containers](#containers)\n- [Types of STL Container in C++](#types)\n- [Sequential Containers](#sequential)\n- [Associative Containers](#associative)\n- [Unordered Associative Containers](#unordered)\n- [Sequential Exampple](#sequential_example)\n- [Associative Example](#associative_example)\n- [Unordered Exampple](#unordered_example)\n\n### Related links:\n- https://www.scaler.com/topics/cpp/containers-in-cpp/\n\n\u003ca id=\"stl\"\u003e\u003c/a\u003e\n# What is STL\n\nSTL (standard template library) is a software library for the C++ language that provides a collection of templates representing containers, iterators, algorithms, and function objects. In this tutorial, you will learn about C++ STL in detail.\n\nSTL has 4 major components:\n\n- Algorithms\n- Containers\n- Functors\n- Iterators\n\n\u003ca id=\"containers\"\u003e\u003c/a\u003e\n# STL Containers\n\nA Standard Template Library (STL) container in C++ is a template class or type that provides a way to store and organize elements of the same or different types. \n\nThese containers implement various data structures and algorithms for common tasks, offering a high level of abstraction and providing a consistent interface. \n\nSTL containers play a crucial role in C++ programming by offering efficient and reusable solutions for managing collections of data.\n\nContainers abstract away the underlying data structure and implementation details, allowing programmers to focus on algorithms and logic without worrying about low-level details.\n\n\u003ca id=\"types\"\u003e\u003c/a\u003e\n# Types of STL Container in C++\n\nIn C++, there are generally \u003cins\u003e3 kinds of STL containers\u003c/ins\u003e:\n\n   - **Sequential Containers**\n   - **Associative Containers**\n   - **Unordered Associative Containers**\n\n ![image](https://github.com/izzypt/CPP_Module_08/assets/73948790/8869a758-5c09-4093-aaec-f0fe201b1778)\n\n\n\u003ca id=\"sequential\"\u003e\u003c/a\u003e\n# Sequential Containers in C++\n\nIn C++, \u003cins\u003esequential containers allow us to store elements that can be accessed in sequential order\u003c/ins\u003e.\n\nInternally, sequential containers are implemented as arrays or linked lists data structures.\n\nTypes of Sequential Containers\n\n   - **Array**\n   - **Vector**\n   - **Deque**\n   - **List**\n   - **Forward List**\n\n![image](https://github.com/izzypt/CPP_Module_08/assets/73948790/6d8f1d41-c2c2-451e-a3b1-6459452de18b)\n\n\n\u003ca id=\"associative\"\u003e\u003c/a\u003e\n# Associative Containers in C++\n\nIn C++, associative containers \u003cins\u003eallow us to store elements in sorted order\u003c/ins\u003e. The order doesn't depend upon when the element is inserted.\n\nInternally, they are implemented as binary tree data structures.\n\nTypes of Associative Containers\n\n   - **Set**\n   - **Map**\n   - **Multiset**\n   - **Multimap**\n\n![image](https://github.com/izzypt/CPP_Module_08/assets/73948790/07312051-ec3b-47df-897e-b5c3fc13d2e8)\n\n\u003ca id=\"unordered\"\u003e\u003c/a\u003e\n# Unordered Associative Containers in C++\n\nIn C++, STL Unordered Associative Containers provide the unsorted versions of the associative container.\n\nInternally, unordered associative containers are implemented as hash table data structures.\n\nTypes of Unordered Associative Containers\n\n   - **Unordered Set**\n   - **Unordered Map**\n   - **Unordered Multiset**\n   - **Unordered Multimap**\n\n\u003ca id=\"sequential_example\"\u003e\u003c/a\u003e\n# Sequential Container Example\n\nIn this example, we will be using the vector class to demonstrate the working of a sequential container.\n\n```cpp\n#include \u003ciostream\u003e\n#include \u003cvector\u003e\nusing namespace std;\n\nint main() {\n\n  // initialize a vector of int type\n  vector\u003cint\u003e numbers = {1, 100, 10, 70, 100};\n\n  // print the vector\n  cout \u003c\u003c \"Numbers are: \";\n  for(auto \u0026num: numbers) {\n    cout \u003c\u003c num \u003c\u003c \", \";\n  }\n\n  return 0;\n}\n```\n\nOutput:\n\n```cpp\nNumbers are: 1, 100, 10, 70, 100,\n```\nIn the above example, we have created sequential container numbers using the vector class.\n\n```cpp\nvector\u003cint\u003e numbers = {1, 100, 10, 70, 100};\n```\nHere, we have used a ranged for loop to print each element of the container.\n\nIn the output, we can see the numbers are shown in sequential order as they were initialized.\n```cpp\n// output numbers\n1, 100, 10, 70, 100,\n```\n\u003ca id=\"associative_example\"\u003e\u003c/a\u003e\n# Associative Container Example (set)\nIn this example, we will be using the set class to demonstrate the working of an associative container.\n\n```cpp\n#include \u003ciostream\u003e\n#include \u003cset\u003e\nusing namespace std;\n\nint main() {\n\n  // initialize a set of int type\n  set\u003cint\u003e numbers = {1, 100, 10, 70, 100};\n\n  // print the set\n  cout \u003c\u003c \"Numbers are: \";\n    for(auto \u0026num: numbers) {\n      cout \u003c\u003c num \u003c\u003c \", \";\n    }\n\n  return 0;\n}\n```\nOutput:\n\n```cpp\nNumbers are: 1, 10, 70, 100,\n```\nIn the above example, we have created an associative container using the set class.\n\nWe have initialized a set named numbers with unordered integers, along with a duplicate value 100:\n\n```cpp\nset\u003cint\u003e numbers = {1, 100, 10, 70, 100};\n```\nThen we print the content of the set using a ranged for loop.\n\nIn the output, we see that the numbers are sorted in ascending order with duplicate numbers removed. Initially, 100 was repeated twice but the set removes the duplicate number 100.\n\n```cpp\n// output numbers\n1, 10, 70, 100\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fizzypt%2Fcpp_module_08","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fizzypt%2Fcpp_module_08","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fizzypt%2Fcpp_module_08/lists"}