Set in C++
When we want to store unique elements in any data structure then we use set.
Sets are containers that store unique elements following a specific order.
In a set, the value of an element also identifies it (the value is itself the key, of type T), and each value must be unique. The value of the elements in a set cannot be modified once in the container (the elements are always const), but they can be inserted or removed from the container.
Internally, the elements in a set are always sorted following a specific strict weak ordering criterion indicated by its internal comparison object (of type Compare).
set containers are generally slower than unordered_set containers to access individual elements by their key, but they allow the direct iteration on subsets based on their value.
Sets are typically implemented as binary search trees.
It have iterator and all other functionalities of any other data structure.
To add elements we use pair method. pair have two values pair.second is a boolean.It contains true when inserted and false when not inserted.
set <string> dataLines; string str(this->m_szCurrentLine); std::pair<std::set<string>::iterator,bool> p; p=dataLines.insert(str);
Latest posts by Shankar Morwal (see all)
- Upgrade node.js version in ubuntu 14 or ubuntu 16 - May 8, 2017
- Angular 4 will be out soon, Everything you need to know - February 20, 2017
- Installing teamcity 10.0.4 on ubuntu server - January 17, 2017