Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
A

atreya

@atreya
About
Posts
1
Topics
0
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Which container should i choose
    A atreya

    Hello, STL 'std::set' best suits :eek: your application based on what you have explained. 'std::set' STL has been particularly designed to hold unique elements of a particular datatype. As your container needs to hold only unique values:omg:, you can exploit the 'std::set' STL efficiently. It will also work faster and more efficiently that a vector implementation for your usage since a 'std::set' is specially designed to hold unique elements and a customized find() function exists for 'std::set' that you can use instead of using the generic 'find()' function. This also adds to efficiency.:) I've given a small code snippet here for you::rose: -------------------------------------------------

    #include <set>
    #include <iostream>

    using namespace std;

    int main()
    {
    set set1;

    // insert 10 integers.
    for(int i = 0; i < 10; ++i)
    	set1.insert(i);
    
    cout << "Set contains: ";
    for(set::iterator set\_iter = set1.begin(); set\_iter != set1.end(); ++set\_iter)
    	cout << \*set\_iter << " ";
    cout << endl << endl;
    
    int value\_to\_be\_searched = 5;
    
    set::iterator si = set1.find(value\_to\_be\_searched);
    if(si != set1.end())
    	cout << "Value " << value\_to\_be\_searched << ": found!!" << endl;
    else
    	cout << "Value " << value\_to\_be\_searched << ": not found!!" << endl;
    
    value\_to\_be\_searched = 14;
    
    si = set1.find(value\_to\_be\_searched);
    if(si != set1.end())
    	cout << "Value " << value\_to\_be\_searched << ": found!!" << endl;
    else
    	cout << "Value " << value\_to\_be\_searched << ": not found!!" << endl;
    
    return 0;
    

    }

    ------------------------------------------------- Bye, Chaitanya Atreya. Whenever I hear someone sighing "Life is hard", I'm tempted to ask "Compared to what?".

    C / C++ / MFC graphics sysadmin docker help question
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups