set

Started by
2 comments, last by Pzc 16 years, 12 months ago
I FOUND set has only a key without value. where is value. in general, key and value come with in pair.
Advertisement
The key is the value.

In a map, you have the pair and the data-structure is sorted only on the key.
In a set, you have a value and the data-structure is sorted only on that value.

map:[1,"one"] [2,"two"] [3,"three"]set:[1] [2] [3]


Both of these sort on 1,2, and 3. The map just has extra data attached to each node.
I assume you are talking about the C++ std::set? Indeed, it only has a 'key' because the key is the value. If you want an associative container, use std::map


jfl.


[Edit: Aw shucks, too slow on dem 'Submit Reply']
A nice description about std::set can be found here.
Copy+pasted from the link:
Quote:
Set is a Sorted Associative Container that stores objects of type Key. Set is a Simple Associative Container, meaning that its value type, as well as its key type, is Key. It is also a Unique Associative Container, meaning that no two elements are the same.

This topic is closed to new replies.

Advertisement