n00b question regarding the Map Class in the STL library

This is a discussion on n00b question regarding the Map Class in the STL library within the C++ Programming forums, part of the General Programming Boards category; I was looking at the example sections in the examples of the Vector Class from the STL library, in particular, ...

  1. #1
    Registered User Axegrinder#9's Avatar
    Join Date
    Dec 2005
    Posts
    1

    n00b question regarding the Map Class in the STL library

    I was looking at the example sections in the examples of the Vector Class from the STL library, in particular, of the Map Class. The example given of a student name with an associated letter grade maybe achieved by creating a student object of a class say Student with properties "username" and "grade", and then creating another class which includes the an array of student objects.

    How is storing the data more efficient by using the Map Class more as opposed to creating an object as specified?

  2. #2
    Dae
    Dae is offline
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    Theres no relation between storing in a map or making it an object, because a map is meant for keeping track of data that you dont know off hand (searching, replacing, adding, etc).

    You mean storing in an array vs a map? In my explanation elements = students.

    Assuming you're searching ("given a students name"), and the data in map is sorted (which it should be). A map takes O(log n) times to find an element, it elimates half of the elements left because it chooses left or right branch (because its sorted). In an array it will take on avarage O(n/2) because it has to look at every element in the array.

    For a little amount of elements (less than 50-100) to store the difference in speed is little, but in a large amount of elements you're eliminating a lot in a map and its much faster than an array.
    Last edited by Dae; 12-17-2005 at 05:38 PM.
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    I think you should reread your post because it's nonsensical. It's always a good idea to use the preview feature to check to make sure that your post makes sense.

    A map is like an array except that you can use strings(or objects) as the index values rather than integers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 01-13-2008, 04:57 PM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. Help with Class Library .NET and Classes :0
    By Robert_Sitter in forum Windows Programming
    Replies: 2
    Last Post: 11-27-2005, 07:42 PM
  4. Searching STL Map Inside STL Map Object :: C++
    By kuphryn in forum C++ Programming
    Replies: 2
    Last Post: 11-14-2002, 08:11 AM
  5. Using the STL map for one's own class
    By SilentStrike in forum C++ Programming
    Replies: 2
    Last Post: 09-21-2001, 08:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21