Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

a STL std::set does not store the elements in the same sequence as it is input, rather it stores the elements sorted. Can anyone suggest any idea of displaying the contents of the set unsorted (in the input sequence).

Thank you.
Posted
Updated 16-Jun-10 0:52am
v4
Comments
Moak 15-Jun-10 7:02am    
Updated subject and tags, hope this is what you are looking for. Perhaps use an unsorted STL container instead.

Take a look at Boost.MultiIndex[^] library.
 
Share this answer
 
You need an auxiliary container (with all the caveats of the case).
:)
 
Share this answer
 
Comments
Prasad A 15-Jun-10 8:11am    
Since std::set is an associative container, does it mean that it is not possible to print the the contents unsorterd(in input sequence) ??
CPallini 15-Jun-10 8:47am    
The input sequence (unless already sorted) is lost on insertion.
If you want to store a bunch of elements unsorted may I humbly recommend using either std::vector (if you know roughly how many elements you're going to add) or std::list? Both of them provide a push_back function that'll preserve the insertion order for you.

[Oh, and you'll have to find some other way of checking for uniqueness as well if that was why you were using std::set in the first place.]

Cheers,

Ash
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900