Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Types of STL Containers

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 569
    Comment on it

    STL stands for Standard Template Library. This is a container used to store collection of similar objects. While declaring the container variable, we need to determine the type of element that container will hold. Adding and removing is done by the container.

    There are three types of STL containers:-

    • Adaptive containers
    • Associative containers
    • Sequence containers

    1. ADAPTIVE CONTAINERS- Adaptive containers are different from associative and sequence containers. In adaptive containers we can use any sequence container which we want to use. Container adapters do not support iterators.

    e.g of adaptive containers are stack, queue etc.

    Stack is a container in which elements are pushed and popped from the end of the container.

    Queue is a container in which elements are pushed and popped from the front of the container.

     

    2. ASSOCIATIVE CONTAINERS- In associative containers when input is inserted into the container, the input is automatically sorted by the container. In this elements are accessed using key.

    e.g of associative container is set and map.

    A set stores unique elements, where value is also the key(means no duplicate of that).

    A map consist of key/value pair and key is used to order the sequence.

    Map and set allows only one occurrence/item in the container. For multiple items we use multimap or multiset.

     

    3. SEQUENCE CONTAINERS- Sequence container maintains the order of elements in the container. We can choose the position where we want to insert the element.

    e.g of sequence container is array, deque, list etc.

    An array container implements at compile time and it is non-resizeable.

    A vector container is like an array but can be resizeable means length is flexible. It is accessed randomly, this is the reason it is used mostly.

    A list is doubly linked list, cam be accessed from both the directions. Elements are pushed and popped fast.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: