Well that depends on actual data. If your data are not in form key/value than maybe it's better to use set container. Here's one quick and dirty example:Originally Posted by Daved
I don't think that vector container would be good solution. You insert elements (needs time), sort elements (needs time) and then search for one particular element (needs time). Using set, map or multimap data are automatically sorted when inserted into container. Search of such structure is logarithmic (since it's basically binary search tree "under the hood") because it involves binary search.Code:#include <iostream> #include <set> using namespace std; int main ( ) { set <int> iSet; for (int i = 0; i < 10; i++) { iSet.insert(rand()%100); } set <int> :: iterator it; for (it = iSet.begin(); it != iSet.end(); ++it) { cout << *it << " "; } return 0; }