vectoralgos.cc


	    

	  

              

            

            

STL list

  • A generic doubly-linked list
    • http://www.cplusplus.com/reference/stl/list/
    • Elements are not stored in contiguous memory locations
      • Does not support random access (e.g. cannot do list[5])
    • Can iterate forwards or backwards
    • Some operations are much more efficient than vectors
      • Constant time insertion or deletion anywhere in a list
    • Has a built-in sort member function
      • Doesn't copy! Manipulates list structure instead of element values.

listexample.cc


            

          

              

            

            

STL map

  • One of C++'s associative containers: a key/value table, implemented as a search tree
    • http://www.cplusplus.com/reference/stl/map/
    • General form: map <key_type, value_type> name;
    • Keys must be unique
    • Efficient lookup and insertion (both O(log n))
      • Access value via name[key]
    • Elements are type pair<key_type, value_type> and are stored in sorted order (key is field first, value is field second)
      • Key type must support less-than operator (<)
      • Key type doesn't need to support any hashing

mapexample.cc