Set (C++)
Appearance
C++ Standard Library |
---|
Containers |
C standard library |
Defination
- A set is an associative container data structure that is available as part of the C++ Standard Library (STL), and contains a sorted set of unique objects.[1]
Introduction
Although the abstract concept of a set does not necessarily imply an ordered collection, the standard library set data structure is always ordered. Its functionality in the STL is provided as a template class, such that any valid C++ object can be used with it. Sets are guaranteed to perform operations of insertion, deletion, and testing whether an element is in it, in logarithmic time - O(log n). As such, they are typically implemented using self-balancing binary search trees and support's bidirectional iterator
Types
There are 2 types of sets available in the C++ STL - Sets and Multisets.
Set
- Every element is unique and insertions of values that are already present in the container are ignored.
Multiset
- In the multiset container however, multiple occurrences of the same value are allowed.
Characteristic
- Unique element Value :- In a set no two values are same.
- Element value is itself
- Elements follow strick weak ordering at all times.
References
- ^ ISO/IEC 14882:2011 draft specification, p. 806, § 23.4.6