Caveman's Blog

My commitment to learning.

STANDARD TEMPLATE LIBRARY (STL)

leave a comment »


CONTAINERS

String, List, Vector , Hash, Map, Multimap, Set,

String – #include
A string is a collection of ascii characters that supports both insertion and removal.

List vs Vector – #include “list” vs #include “vector”

Both of them can store collection of objects and work almost similarly.

Lists are double-linked lists. Where as a vector is sequential in memory like an array. Insertion at either end, or in the middle (providing you know an existing element in the middle) is equally fast. Also, splicing is fast (eg. putting a list into the middle of another) – all that does is re-arrange the end pointers. All of those operations would be slower with vectors, because you would need to copy everything. However, vectors shine in random access – since they are organised sequentially in memory, whilst this is slow for insertion at anywhere other than the end, you can easily find, say, element 500, you simply index into the vector. Thus, vectors can be sorted, shuffled, and accessed randomly.

Map – #include “map”
A collection for a varying length sequence of elements of type pair. The first element of each pair is the sort key and the second is its associated value. The sequence is represented in a way that permits lookup, insertion, and removal of an arbitrary element. The key can be a simple as a number or string or as complex a key class. The key class must support normal comparison operations so that the collection can be sorted or searched.

Set – #include “set”
A collection that controls a varying length sequence of elements of type const Key. Each element serves as both a sort key and a value. The sequence is represented in a way that permits lookup, insertion, and removal of an arbitrary element.

Multimap – #include “map”
A collection of a varying length sequence of elements of type pair. The first element of each pair is the sort key and the second is its associated value. The sequence is represented in a way that permits lookup, insertion, and removal of an arbitrary element.

Multiset – #include
A collection of a varying-length sequence of elements of type const Key. Each element serves as both a sort key and a value. The sequence is represented in a way that permits lookup, insertion, and removal of an arbitrary element.

ALLOCATORS

Iterators

Iterators support the access of elements in a collection. They are used throughout the STL to access and list elements in a container. The iterators for a particular collection are defined in the collection class definition.

Advertisements

Written by cavemansblog

January 30, 2008 at 3:30 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: