A Guide To STL

  • STL introduction
  • Components of STL
  • Containers
  • Algorithm
  • Iterators

Introduction:

Yes…Of course! We can implement it by using Standard Template Library.

Components of STL:

1. Containers:

  • An object that stores data in memory into an organized fashion.
  • The containers in STL are implemented by template classes and therefore can be easily modified and customized to hold different types of data.

2. Procedure (Algorithms)

  • Algorithms are used to process the data contained in the containers .
  • The STL includes many different kinds of algorithms to provide support to tasks such as initializing, searching, copying, sorting, and merging, copying, sorting, and merging.
  • Algorithms are implemented by template functions.

3. Iterator

  • It can be defined as an object that points to an element in a container.
  • Iterators are handled just like pointers.
  • Iterators connect algorithm with containers and play a key role in the manipulation of data stored in the containers.

Containers:

  • Description: It can be defined as a dynamic array. It permits direct access to any element.
  • Header File: <vector>
  • Iterator: Random access
  • Description: It is a bidirectional linear list. It allows insertion and deletion anywhere
  • Header File: <list>
  • Iterator: Bidirectional
  • Description: It is a double-ended queue. Allows insertions and deletions at both the ends. Permits direct access to any element.
  • Header File: <deque>
  • Iterator: Random access
  • Description: It is an associate container for storing unique sets. Allows rapid lookup.
  • Header File: <set>
  • Iterator: Bidirectional
  • Description: It is an associate container for storing non-unique sets.
  • Header File: <set>
  • Iterator: Bidirectional
  • Description: It is an associate container for storing unique key/value pairs. Each key is associated with only one value.
  • Header File: <map>
  • Iterator: Bidirectional
  • Description: It is an associate container for storing key/value in which one key may be associated with more than one value (one-to-many mapping). It allows a key-based lookup.
  • Header File: <map>
  • Iterator: Bidirectional
  • Description: A standard stack follows last-in-first-out(LIFO)
  • Header File: <stack>
  • Iterator: No iterator
  • Description: A standard queue follows first-in-first-out(FIFO)
  • Header File: <queue>
  • Iterator: No iterator
  • Description: The first element out is always the highest priority element
  • Header File: <queue>
  • Iterator: No iterator

Algorithm:

  • They are functions that can be used generally across a variety of containers for processing their content.
  • Standard algorithms permit us to work with two different types of containers at the same time.
  • It saves a lot of time and effort of programmers
  • #<algorithm> is the header file used to access STL algorithms.

Iterators:

  • Iterators connect containers with algorithms and play a vital role in the manipulation of data stored in the containers.
  • They are often used to pass through from one element to another, this process is called iterating through the container.
  • There are five types of iterators:

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Want to have an effective Site Reliability Engineering Team ?

Leetcode#89. Gray Code

IValue: efficient representation of dynamic types in C++

ZLogger — Zero Allocation Logger for .NET Core and Unity

How to use WorkManager with RxJava

Download a FREE Header & Footer for Divi’s Pizzeria Layout Pack

19coders

Offline Sync For Smarter Applications

Activity Patterns

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Shivani Sundriyal

Shivani Sundriyal

More from Medium

Minimum Insertions to Balance a Parentheses String

[LeetCode] (Easy) 27. Remove Element

How Are AI And Machine Learning Revolutionizing Software Development?

Leetcode — What is a Palindrome?