{"id":18762807,"url":"https://github.com/imabhinavdev/cpp","last_synced_at":"2025-10-07T12:47:09.246Z","repository":{"id":153868311,"uuid":"440202820","full_name":"imabhinavdev/cpp","owner":"imabhinavdev","description":null,"archived":false,"fork":false,"pushed_at":"2024-03-21T07:09:53.000Z","size":124,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-20T18:58:16.241Z","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/imabhinavdev.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}},"created_at":"2021-12-20T14:40:22.000Z","updated_at":"2024-01-12T18:25:25.000Z","dependencies_parsed_at":null,"dependency_job_id":"66affb5f-985f-41d4-979c-289fb6ebd4c0","html_url":"https://github.com/imabhinavdev/cpp","commit_stats":null,"previous_names":["imabhinavdev/cpp"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/imabhinavdev/cpp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imabhinavdev%2Fcpp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imabhinavdev%2Fcpp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imabhinavdev%2Fcpp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imabhinavdev%2Fcpp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/imabhinavdev","download_url":"https://codeload.github.com/imabhinavdev/cpp/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imabhinavdev%2Fcpp/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278778962,"owners_count":26044256,"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","status":"online","status_checked_at":"2025-10-07T02:00:06.786Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-07T18:23:28.399Z","updated_at":"2025-10-07T12:47:09.193Z","avatar_url":"https://github.com/imabhinavdev.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Containers\n## Pairs\n\n```cpp\npair\u003cint,string\u003e p;\np=make_pair(3,\"abc\");\np={4,\"cde\"};\ncout\u003c\u003cp.first\u003c\u003cp.second\u003c\u003cendl;\n```\n#### Pair Array\n\n```cpp\npair\u003cint,int\u003e p[3];\np[0]={1,4};\n```\n\n```cpp\npair\u003cint,string\u003e p[3];\nswap(p[0],p[1]);\ncin\u003e\u003ep.first;\ncin\u003e\u003ep.second;\n```\n\n## Vectors\n\nDynamic Array\n* Vector Push\n* Vector Pop\n* Vector Size\n* Vector Reference\n\n```cpp\nvector \u003cint\u003e v;\nv.push_back(); //O(1)\nv.pop_back();\ncout\u003c\u003cv.size(); //O(1)\nvector \u003cint\u003e v1(10); //all values will be v1\nvector \u003cint\u003e v2(10,3); //all valuse will be 3\nvector\u003cint\u003e \u0026v3=v2 //passing reference\nvector \u003cint\u003ev2=v1 //O(n) we can use assignment operator here;\nvector \u003cstring\u003es;\n```\n\n* Nested Vector\n```cpp\nvector\u003cpair\u003cint,int\u003e\u003ev;\nv.push_back({1,2});\nv.push_back(make_pair(1,2));\nvector\u003cvector\u003cint\u003e\u003e nestV;\n```\n\n### Iterators\n* .begin()\n* .end()\n\n\u003e it++ this moves to the next **Iterator**  but it+1 moves it to the next **Location**. It it+1 cannot work in map and sets and locations are not continous.\n\n```cpp\nvector \u003cint\u003ev;\nv.push_back(10);\nvector \u003cint\u003e:: iterator it=v.begin()\ncout\u003c\u003c*it\u003c\u003cendl;\nfor(it=v.begin();it!=v.end;++it)\n{\n    cout\u003c\u003c(*it);\n}\n\nvector\u003cpair\u003cint,int\u003e\u003e vp;\nvector\u003cpair\u003cint,int\u003e\u003e::iterator it1;\ncout\u003c\u003c(*it1.first);\ncout\u003c\u003c(it1-\u003efirst);\ncout\u003c\u003c(it1-\u003esecond);\n\n//it1-\u003efirst == *it1.first\n```\n\n#### Iterator using C++ 11 | Auto Keyword\n* Range Based Loops\n\n```cpp\nvector\u003cint\u003ev;\nfor(int val:v)\n{\n    value++;//value is copied not referenced\n    cout\u003c\u003cval;\n}\nfor(int \u0026val:v)\n{\n    value++;//value is referenced\n    cout\u003c\u003cval;\n}\n\nvector\u003cpair\u003cint,int\u003e\u003evp;\nfor(pair\u003cint,int\u003e \u0026val:vp)\n{\n    cout\u003c\u003cval.first\u003c\u003c\" \"\u003c\u003cval.second;\n}\n```\n\n* **Auto Keyword**\n\nAuto Keyword can automatically understands the datatype. \n\n```cpp\nauto a=1;\nauto b=\"abc\";\nauto c=1.0;\nvector\u003cpair\u003cint,int\u003e\u003evp;\nfor(auto \u0026val:vp)\n{\n    cout\u003c\u003cval.first\u003c\u003c\" \"\u003c\u003cval.second;\n}\n```\n\n\n## Maps\n1. Maps (ordered)(red Black trees)\n2. Unordered Maps \n\nKey-value pair is stored.\n* .size() - gievs the size of the map.\n\n```cpp\nmap\u003cint,string\u003e m;\nm[1]=\"abc\"; //O(logn)\nm[5]=\"cde\";\nm[2]=\"efg\";\nm.insert({4,\"afg\"});\nmap\u003cint,string\u003e::iterator it;\nfor(auto \u0026val:m)\n{\ncout\u003c\u003cval.first\u003c\u003c\" \"\u003c\u003cval.second;\n}\ncout\u003c\u003cm.size(); //prints m size.\nauto itt=m.find(3);//returns iterator else returns m.end(). O(log n)\n\nm.erase(5);//removes keys and values\nm.erase(m.find(3));\nm.clear(); //clears everything\n```\n\n\u003eInsertion of keys of string is **string.size()\\*log(n)**\n\n#### Unordered Maps\n\n`Unorderd Map cannot work on pairs!`\n\n\u003eUse Hash Tables in this.\n\u003eO(1) is time complexity\n\nEvery method is taking O(1) like find(),erase()\n\n```cpp\nunordered_map\u003cint,string\u003e m;\n```\n\n## Sets\n1. Sets\n2. Unordered Sets\n3. Multiset\n\n```cpp\nset\u003cstring\u003e s;\ns.insert(\"avc\"); //log(n)\ns.insert(\"def\");\ns.insert(\"ghi\");\nauto it=s.find(\"abc\")//O(log(n)) returns iterator else returns s.end()\ns.erase(\"avc\");//removes the record.\n```\n\n#### Multiset\n\n```cpp\nmultiset\u003cstring\u003e s;\ns.find(); //returns the iterator of first match.\ns.erase('abc');// delete all values abc or else if we pass the iterator then it will delete only one\n\n```\n\n\n## Stacks\n\n```cpp\nstack\u003cint\u003e a;\na.push(3);\na.push(4);\na.push(5);\na.pop();\n```\n\n## Queues\n\n```cpp\nqueue\u003cint\u003e q;\nq.push(4);\nq.push(5);\nq.empty();\n\nq.front(); //prints the front value\nq.pop();\n```\n\n### Sorting\n\n```cpp\nsort(starting address, last address+1); //O(nlog(n))\n```\n\n``Follow Intro Sort is used in STL.``\n\n\n## Upper Bound and Lower Bound\n\nArrays or vectors should be sorted.\n#### Lower Bound\nIf the value is present in array or vector than it returns that value and if not present then it returns the value greater then the input that is present in the array.\n\n#### Upper Bound\nReturns the value more than the input value in the array.\n\n```cpp\nint arr[5];\nint *ptr=lower_bound(a,a+n,5);//returns the pointer \nint *ptr1=lower_bound(a,a+n,5);//returns the pointer of element greater than 5.\n```\n\n\n### Minimum and Maximum Element\n\n```cpp\nvector\u003cint\u003e v;\nint min=*min_element(v.begin(),v.end());//returns pointer.\nint max=*max_element(v.begin(),v.end());//returns pointer.\n```\n\n### Accumulate\nSums the array.\n```cpp\nvector\u003cint\u003ev;\nint sum=accumulate(v.begin(),v.end(),initialSum);//initial sum should be 0 for arrray sum\n```\n\n### Count and Find, Reverse\nCounts the element count.\n\n```cpp\nvector\u003cint\u003e v;\nint ct=count(v.begin(),v.end(),3);\nint ele=*find(v.begin(),v.end(),2);//returns iterator\nauto ele=find(v.begin(),v.end(),2);//returns iterator\n\nif(ele !=v.end())\n{\n    cout\u003c\u003c*it;\n}\n\n\nreverse(v.begin(),v.end()); //reverse vector or string\n```\n\n### Lambda Function\n\n```cpp\ncout\u003c\u003c[](int x,int y){return x+y;}(2,4);\n```\n\n\n### All of, None Of, Any of\n\nAll of\n\n```cpp\nvector\u003cint\u003e v;\ncout\u003c\u003call_of(v.begin(),v.end(),[](int x){return x\u003e0;}); //if all true then true else false\ncout\u003c\u003cany_of(v.begin(),v.end(),[](int x){return x\u003e0;}); //if any true then true else false\ncout\u003c\u003cnone_of(v.begin(),v.end(),[](int x){return x\u003e0;}); //if none are true then true else false\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimabhinavdev%2Fcpp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimabhinavdev%2Fcpp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimabhinavdev%2Fcpp/lists"}