Set (C++): Difference between revisions
No edit summary |
|||
Line 18: | Line 18: | ||
*[[Element]] value is itself a [[key]]. |
*[[Element]] value is itself a [[key]]. |
||
*Elements follow strict weak ordering at all times. |
*Elements follow strict weak ordering at all times. |
||
==Function's in Set== |
|||
In a [[Set (computer science)|set]] container various functions are used. Some of them are as follows: |
|||
===begin=== |
|||
[[Function]] begin() is used to return an [[iterator]] to the first element.It is [[constant time]] function. |
|||
*Syntax |
|||
<Source lang="c"> |
|||
#include<set> |
|||
iterator begin(); |
|||
const_iterator begin const; |
|||
</source> |
|||
===end=== |
|||
The [[function]] end() will return an [[iterator]] just before the end of the set. It is [[constant time]] function. |
|||
*Syntax |
|||
<Source lang="c"> |
|||
#include<set> |
|||
iterator end(); |
|||
const_iterator end() const; |
|||
</source> |
|||
===rbegin=== |
|||
function will return a reverse iterator to the end of current set. It is constant time function. |
|||
syntax |
|||
<Source lang="c"> |
|||
#include<set> |
|||
reverse iterator rbegin(); |
|||
const_reverse_iterator rbegin() const; |
|||
</source> |
|||
==References== |
==References== |
Revision as of 18:12, 14 September 2011
C++ Standard Library |
---|
Containers |
C standard library |
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]
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: Set and Multiset.
Set
In a set, every element is unique, and insertions of values that are already present in the container are ignored.
Multiset
In a multiset, multiple occurrences of the same value are allowed.
Characteristics
- Unique element value: In a set, no two values are same.
- Element value is itself a key.
- Elements follow strict weak ordering at all times.
Function's in Set
In a set container various functions are used. Some of them are as follows:
begin
Function begin() is used to return an iterator to the first element.It is constant time function.
- Syntax
#include<set>
iterator begin();
const_iterator begin const;
end
The function end() will return an iterator just before the end of the set. It is constant time function.
- Syntax
#include<set>
iterator end();
const_iterator end() const;
rbegin
function will return a reverse iterator to the end of current set. It is constant time function. syntax
#include<set>
reverse iterator rbegin();
const_reverse_iterator rbegin() const;
References
- ^ ISO/IEC 14882:2011 draft specification, p. 806, § 23.4.6