Which STL datastructure for O(log n) search ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Digital Don
    New Member
    • Jan 2007
    • 19

    Which STL datastructure for O(log n) search ?

    Hi,

    Iwas trying to look for a STL datastructure in C++ where I can store structure variables and then get out value from it by just comparing the value as follows;

    The structure variable: "strctvar";
    The STL datastructure: "STLstruct" ;

    Storing multiple different of "strctvar"s into "STLstruct" ;

    to get a particular value of "strctvar" in "STLstruct" , I want it to be as simple as

    newstrctvar = STLstruct.value ("xyz") ;

    where "xyz" is a value of"name" in the structure

    struct
    {
    string name;
    int x;
    }strctvar;

    Is any thing like this possible...

    I think I am asking too much...but I think there i something like this in STL but cant find which one is it. So please help me find the one..

    Thank You in Advance
  • Ganon11
    Recognized Expert Specialist
    • Oct 2006
    • 3651

    #2
    The STL set class is implemented with a sort of Binary Search Tree (I think an optimized Red-Black tree), and most (if not all) of its operations are guaranteed O(log n) time. Searches are definitely O(log n).

    Comment

    • Digital Don
      New Member
      • Jan 2007
      • 19

      #3
      Thank You for the reply. I think this will help me.

      I am new using the STL structures and am enjoying learning all these stuff...These make out work so easy..

      Comment

      Working...