Introduction to C++ Containers Vector, List, Set, Map in hindi
C++ प्रोग्रामिंग लैंग्वेज में डेटा स्ट्रक्चर इसके यूजर को कई प्रकार के रिच सेट डाटा टाइप प्रोवाइड करता है, जिसे C++ में बिल्ट-इन स्टैंडर्ड टेम्पलेट लाइब्रेरी (STL) कंटेनर के नाम से ऐड किया जाता है. जो C++ यूजर को डेटा के कलेक्शन इनफार्मेशन को प्रॉपर आर्डर में स्टोर और मैनिपुलेट करने में हेल्प करते है। ये C++ कंटेनर डाटा टाइप C++ प्रोग्रामिंग स्टैंडर्ड लाइब्रेरी में vector, list, set, map, और अन्य हेडर फाइल का बिल्ट-इन फीचर्स हैं। C++ में vector, list, set, map आदि कोई भी कंटेनर एक स्पेशल पर्पस के लिए यूज़ होता है, और इन vector, list, set, map, डाटा टाइप को मल्टीप्ल इंडिविजुअल पर्पस के लिए C++ में ऑप्टिमाइज़ किया जाता है।

So, let’s learn in detail about the most commonly used vector, list, set, and map data type containers in C++.
Vector Data Type Concept in C++.
C++ प्रोग्रामिंग में वेक्टर एक डायनामिक ऐरे डाटा टाइप कांसेप्ट है, जो मौजूदा प्रोग्राम में किसी वेक्टर एलिमेंट को ऐड करने या डिलीट करने पर अपने आप अपने डिफ़ॉल्ट साइज़ को मॉडिफाई कर सकता है। वेक्टर डाटा टाइप इंडेक्स मेथड का यूज़ करके इसके स्टोर्ड डाटा एलिमेंट को इमीडियेट फ़ास्ट एक्सेस कर सकते है, और वेक्टर उन कंडीशंस के लिए सबसे बेस्ट चॉइस है. जहाँ C++ प्रोग्रामर को रैंडम डाटा इनफार्मेशन एक्सेस करने की ज़रूरत होती है।
Important Features of the Vector Data Type.
- Dynamic resizing – वेक्टर डाटा टाइप में एक नया एलिमेंट ऐड करने पर यह अपने आप इसके साइज़ को मॉडिफाई कर सकता है।
- Efficient random access – वेक्टर डाटा टाइप स्टोरेज एलिमेंट को इसके इंडेक्स से एलिमेंट लोकेशन से एक्सेस करने के लिए O(1) टाइम मेथड को यूज़ करता है.
- Efficient at the end – यह वेक्टर डाटा टाइप में एक नया एलिमेंट को लास्ट में ऐड या डिलीट O(1) लोकेशन पर करता है।
- Doesn’t work properly from the front – इसमें वेक्टर डाटा टाइप के स्टार्ट या मध्य में एक नया एलिमेंट इन्सर्ट या डिलीट करने के लिए एलिमेंट को शिफ्ट करना पड़ता है, जिससे यह O(n) शिफ्ट हो जाता है।
Example of using vector in C++ programming.
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<int> vctr; // here we declaring a vector of integers numbers
// here we adding elements to the vector database element
vctr.push_back(89); // here we adds 89 to the vector end
vctr.push_back(23); // here we adds 23 to the end
vctr.push_back(77); // here we adds 77 to the end
vctr.push_back(01); // here we adds 01 to the end
// here it accessing vector elements using indices index storage location method
cout << “First element of vector – ” << vctr[0] << endl; // 89
cout << “Second element of vector – ” << vctr.at(1) << endl; // 23
cout << “Last element of vector – ” << vctr.at(3) << endl; // 01
// here it Iterating through the vector data element
cout << “All Element of Vector data is – “;
for (int p = 0; p < vctr.size(); p++) {
cout << vctr[p] << ” “;
}
cout << endl;
// here it removing last vector element
vctr.pop_back(); // here it removes 01
return 0;
}
List Data Type Concept in C++.
C++ प्रोग्रामिंग लैंग्वेज में लिस्ट डाटा टाइप एक डबल लिंक्ड लिस्ट कंटेनर डाटा स्टोरेज मेथड होती है, जो दोनों सिरों स्टार्ट और एन्ड और बीच में डाटा एलिमेंट को प्रॉपर आर्डर में इन्सर्ट और डिलीट करने के फीचर्स प्रोवाइड करता है। जैसाकि, लिस्ट डाटा टाइप में रैंडम डाटा एलिमेंट एक्सेस सपोर्टेड नहीं है. लिस्ट डाटा टाइप इसके एलिमेंट को एक्सेस करने के लिए पूरी लिस्ट डाटा में उसे प्रॉपर इटरेट करना पड़ता है।
Important Features of the list data type.
- Straightforward insertion and removal – लिस्ट डाटा टाइप में किसी भी जगह (लिस्ट के स्टार्ट, मिडिल या लास्ट में) में एक नया डाटा एलिमेंट इन्सर्ट और डिलीट करना O(1) लोकेशन है।
- No random access – जरूरत पड़ने पर लिस्ट डाटा एलिमेंट को एक्सेस करना O(n) है, इसके लिए आपको लिस्ट डाटा में लूप के माध्यम से इटरेट करना होगा।
- Memory overhead – लिस्ट डाटा टाइप में हर डाटा एलिमेंट को एक्स्ट्रा पॉइंटर्स (नेक्स्ट और प्रीवियस) आर्डर में स्टोर करना होगा।
Example of using the list data type.
#include <iostream>
#include <list>
using namespace std;
int main() {
list<int> lst; // here we declaring a list of integers data type element
// here we adding elements to the list data type
lst.push_back(34); // here it adds 34 to the active list end
lst.push_back(55); // here it adds 55 to the active list end
lst.push_front(66); // here it adds 66 to the active list end
lst.push_front(89); // here it adds 89 to the front active list
// here it Iterating through the list element
cout << “Element of List contents is – “;
for (int n : lst) {
cout << n << ” “;
}
cout << endl;
// here it removing the list elements
lst.pop_front(); // here it removes the first list element (89)
lst.pop_back(); // here it removes the last list element (55)
cout << “After popping (Remove) front and back list element – “;
for (int n : lst) {
cout << n << ” “;
}
cout << endl;
return 0;
}
Set Data Type Concept in C++.
C++ प्रोग्रामिंग लैंग्वेज में सेट एक एसोसिएटिव डाटा टाइप कंटेनर फीचर्स होता है, जो यूनिक डाटा टाइप एलिमेंट्स को सॉर्टेड ऑर्डर अल्फबेटिकल सीक्वेंस आर्डर में स्टोर करता है। इंटरनल आर्डर में, सेट डाटा टाइप सामान्य रूप से एक बैलेंस्ड बाइनरी सर्च ट्री (जैसे रेड-ब्लैक ट्री) के रूप में इम्प्लीमेंट किया जाता है। सेट डाटा टाइप इसके स्टोरेज में डुप्लीकेट डाटा एलिमेंट स्टोरेज की परमिशन प्रोवाइड नहीं करता और सेट एलिमेंट्स डाटा को ऑटोमैटिकली सॉर्ट कर अरेंज करता है।
Important Features of the Set Data Type.
- Unique element – सेट डाटा टाइप किसी भी प्रकार का कोई डुप्लीकेट वैल्यू अलाउड नहीं करता है।
- Automatic sorting – सेट डाटा टाइप एलिमेंट्स को एक कम्पेरिजन फंक्शन के आधार पर सॉर्टेड ऑर्डर में स्टोर करता है।
- Efficient search – सेट डाटा टाइप में इजी सर्च, इन्सर्ट और डिलीट ऑपरेशन्स के लिए O(log n) टाइम कॉम्प्लेक्सिटी मेथड को यूज़ करता है।
Example of Set data type usage in C++.
#include <iostream>
#include <set>
using namespace std;
int main() {
set<int> sat; // here it declaring a set of integers element
// here it adding elements to the set data type
sat.insert(90);
sat.insert(70);
sat.insert(99);
sat.insert(99); // we add duplicate set element, and this will not to be added in set group
// here it iterating through the set element
cout << “The list of Set element is – “;
for (int n : sat) {
cout << n << ” “; // here set data will automatically sort the elements in ascending order
}
cout << endl;
// here it checking for an set element
if (sat.find(99) != sat.end()) {
cout << “99 is in the set.” << endl;
}
// here it removing an set element
sat.erase(70);
cout << “After removing set 70 element – “;
for (int n : sat) {
cout << n << ” “;
}
cout << endl;
return 0;
}
Map Data Type Concept in C++.
C++ प्रोग्रामिंग लैंग्वेज में मैप एक एसोसिएटिव डाटा टाइप कंटेनर स्टोरेज कांसेप्ट है. जो की-वैल्यू पेयर आर्डर में किसी डाटा वैल्यू को स्टोर और प्रोसेस करता है। मैप डाटा टाइप की के आधार पर की-वैल्यू पेयर्स को प्रॉपर आर्डर में एक्सट्रेक्ट, इन्सर्ट और डिलीट करने की परमिशन प्रोवाइड करता है। सेट डाटा टाइप की तरह ही, मैप डाटा टाइप सामान्य रूप से एक बैलेंस्ड बाइनरी डाटा सर्च ट्री के रूप में अप्लाई किया जा सकता है।
Important Features of the Map Data Type.
- Key-value pairs – मैप डाटा टाइप में हर स्टोर डाटा एलिमेंट एक पेयर होता है, जिसमें एक की और एक वैल्यू डिफाइन होती है।
- Unique keys – मैप डाटा टाइप में हर की यूनिक और सेपरेट होनी चाहिए। लेकिन मैप में कोई वैल्यूज़ को डुप्लिकेट किया जा सकता है।
- Automatic sorting – मैप डाटा एलिमेंट्स को उसके कीज़ के आधार पर सॉर्ट किए गए ऑर्डर में स्टोर और प्रोसेस किया जा सकता है।
- Improved search – मैप डाटा में एलिमेंट सर्च, न्यू डाटा इन्सर्ट और डिलीट ऑपरेशन के लिए O(log n) टाइम कॉम्प्लेक्सिटी कांसेप्ट को यूज़ किया जाता है।
Example of using the map data type in C++.
#include <iostream>
#include <map>
using namespace std;
int main() {
map<string, int> mdata; // here we declaring a map data type of strings to integers values
// here we adding a key-value pairs to the map data type
mdata[“Java”] = 90;
mdata[“Python”] = 70;
mdata[“Matlab”] = 55;
mdata[“Xcode”] = 20;
// here we Iterating through the map data type
cout << “Map data type contents is – “;
for (auto& pair : mdata) {
cout << pair.first << ” -> ” << pair.second << “, “;
}
cout << endl;
// here we accessing map value by key
cout << “The value for key ‘Java’ is – ” << mdata[“Java”] << endl;
cout << “The value for key ‘Xcode’ is – ” << mdata[“Xcode”] << endl;
// here we removing a map key-value pair
mdata.erase(“Python”);
cout << “After delete ‘Python’ map element – “;
for (auto& pair : mdata) {
cout << pair.first << ” => ” << pair.second << “, “;
}
cout << endl;
return 0;
}
Detail summary of vector, list, set, map, Containers in c++
| Container | Data Type method | Key Features elements | TimeComplexity (Access/Search/Insert/Erase) method |
| Vector data type | Storage data type Sequence container method | Used to store dynamic array, fast random access, it can resize with any changes or modification | We can access vector data as O(1) for access, O(n) for insertion/removal at middle location |
| List data type | List data store in Sequence container (doubly linked list) data type method | In list as linked list possible efficient insertions and deletions anywhere in start middle or end | We can access O(n) for access, O(1) for insertion/removal list data in linked list order |
| Set data type | Set data type store element in associative container order | It used to Sorted, unique set data elements | We can access O(log n) for insert, erase, and search data operation in set data type |
| Map data type | Map data type used associative container (key-value pairs) order | Map data type Sorted key-value pairs, unique keys with data elements | We can access map data O(log n) for insert, erase, and search key value pair operation |

