Data Structure with
STL
By:Mohamed Essam
Data Structures
Every child knows that one can – at least beyond a certain
number – find things much easier if one keeps order. We
humans understand by keeping things in order that we separate
the things that we possess into categories and assign fixed
locations to these categories that we can remember.
We may simply throw socks into a drawer, but for other things
like DVDs it is best to sort them beyond a certain number so that
we can quickly find every DVD.
C++ STL
STL stands for Standard Template Library. Alexander Stepanov invented it
in 1994, and later it was included in the standard library. The standard
library consists of a set of algorithms and data structures that were
originally part of the C++ Standard template library.
STL helps in storing and manipulating objects, and it makes the program
reusable and robust.
CONTAINERS
Suppose you are at your favorite cinema hall and it's the launch of a big
movie. Since it's the launch, there are likely many people waiting in line
to buy their tickets. Naturally, you join the queue at the back and wait
for your turn. In the computing world, we have a queue too! This is a
popular data structure. If you've had a Data Structures class before,
you are most likely familiar with some other data structures as well.
These are often used, so the STL provides a great implementation of all
these data structures, otherwise known as containers.
CONTAINERS
Suppose you are at your favorite cinema hall and it's the launch of a big
movie. Since it's the launch, there are likely many people waiting in line
to buy their tickets. Naturally, you join the queue at the back and wait
for your turn. In the computing world, we have a queue too! This is a
popular data structure. If you've had a Data Structures class before,
you are most likely familiar with some other data structures as well.
These are often used, so the STL provides a great implementation of all
these data structures, otherwise known as containers.
CONTAINERS
Suppose you are at your favorite cinema hall and it's the launch of a big
movie. Since it's the launch, there are likely many people waiting in line
to buy their tickets. Naturally, you join the queue at the back and wait
for your turn. In the computing world, we have a queue too! This is a
popular data structure. If you've had a Data Structures class before,
you are most likely familiar with some other data structures as well.
These are often used, so the STL provides a great implementation of all
these data structures, otherwise known as containers.
C++ STL
STL stands for Standard Template Library. Alexander Stepanov invented it
in 1994, and later it was included in the standard library. The standard
library consists of a set of algorithms and data structures that were
originally part of the C++ Standard template library.
STL helps in storing and manipulating objects, and it makes the program
reusable and robust.
Elements of the STL
- Containers
- Collections of objects or primitive types
- [Array, vector, deque, stack, set, map, etc]
- Algorithms
- Functions for processing sequences of elements from containers
- [find, max, count, accumulate, sort, etc]
- Iterators
- Generate sequence of element from containers
- [forward, reverse, by value, by reference, constant, etc.]
CONTAINERS-ARRAYS
But wait, STL provides a container for arrays too. It's available in the
header <array>. Example usage of it would look like this:
CONTAINERS-ARRAYS
But wait, STL provides a container for arrays too. It's available in the
header <array>. Example usage of it would look like this:
CONTAINERS
Take arrays, for example. Arrays are elements with the same type, stored
in contiguous blocks of memory. In C++, you can use arrays as you
would in C, like this:
CONTAINERS-ARRAYS
Take arrays, for example. Arrays are elements with the same type, stored
in contiguous blocks of memory. In C++, you can use arrays as you
would in C, like this:
CONTAINERS-ARRAYS
But wait, STL provides a container for arrays too. It's available in the
header <array>. Example usage of it would look like this:
CONTAINERS-ARRAYS
But wait, STL provides a container for arrays too. It's available in the
header <array>. Example usage of it would look like this:
CONTAINERS-ARRAYS
CONTAINERS-VECTORS
Vector: Dynamically resizable arrays. Arrays have a set size,
while std::vector doesn't. You can keep adding elements in contigious
blocks of memory. For example:
CONTAINERS-VECTORS
Vector: Dynamically resizable arrays. Arrays have a set size,
while std::vector doesn't. You can keep adding elements in contigious
blocks of memory. For example:
CONTAINERS-VECTORS
Vectors are the same as dynamic arrays with the ability to resize itself
automatically when an element is inserted or deleted, with their
storage being handled automatically by the container. Vector elements
are placed in contiguous storage so that they can be accessed and
traversed using iterators. In vectors, data is inserted at the end.
Inserting at the end takes differential time, as sometimes the array
may need to be extended. Removing the last element takes only
constant time because no resizing happens. Inserting and erasing at
the beginning or in the middle is linear in time.
CONTAINERS-VECTORS
CONTAINERS-VECTORS
CONTAINERS-VECTORS
CONTAINERS-VECTORS
CONTAINERS-DEQUE
Deque in C++ is an abbreviation that generally
stands for double ended queue. The queue data
structure is generalised by the Deque and that
basically means the insertion and deletion can be
executed from both the ends that can be either
front or back.
CONTAINERS-DEQUE
Deque in C++ is an abbreviation that generally
stands for double ended queue. The queue data
structure is generalised by the Deque and that
basically means the insertion and deletion can be
executed from both the ends that can be either
front or back.
Forward List
CONTAINERS-DEQUE
Deque in C++ is an abbreviation that generally
stands for double ended queue. The queue data
structure is generalised by the Deque and that
basically means the insertion and deletion can be
executed from both the ends that can be either
front or back.
CONTAINERS-Forward list
Forward list in STL implements singly linked list.
Introduced from C++11, forward list are more
useful than other containers in insertion, removal,
and moving operations (like sort) and allow time
constant insertion and removal of elements.
CONTAINERS-Forward list
Forward list in STL implements singly linked list.
Introduced from C++11, forward list are more
useful than other containers in insertion, removal,
and moving operations (like sort) and allow time
constant insertion and removal of elements.
CONTAINERS-Forward list
Forward list in STL implements singly linked list.
Introduced from C++11, forward list are more
useful than other containers in insertion, removal,
and moving operations (like sort) and allow time
constant insertion and removal of elements.
CONTAINERS-forward list
New in c++
In C++ “new” is an operation that asks the underlying
system to allocate memory to store something.
Generally, that memory will be allocated in the system
heap, but operator new can be overloaded to allocate
memory in other locations (memory pools, custom
memory arenas, etc.). The “something” is what you write
after “new”. In your example: “int”.
Arrow in c++
Difference between Dot(.) and Arrow(->) operator:
The Dot(.) operator is used to normally access members
of a structure or union.
The Arrow(->) operator exists to access the members of
the structure or the unions using pointers.
Arrow in c++
Difference between Dot(.) and Arrow(->) operator:
The Dot(.) operator is used to normally access members
of a structure or union.
The Arrow(->) operator exists to access the members of
the structure or the unions using pointers.
Doubly linked list
We strongly recommend to refer following post as a
prerequisite of this post.
Linked List Introduction
Inserting a node in Singly Linked List
A Doubly Linked List (DLL) contains an extra pointer,
typically called previous pointer, together with next
pointer and data which are there in singly linked list.
CONTAINERS-list
CONTAINERS-list
Stack
Stacks are a type of container adaptors with LIFO(Last In First
Out) type of working, where a new element is added at one end
(top) and an element is removed from that end only.
Stack uses an encapsulated object of
either vector or deque (by default) or list (sequential container
class) as its underlying container, providing a specific set of
member functions to access its elements.
Stack
Stacks are a type of container adaptors with LIFO(Last In First
Out) type of working, where a new element is added at one end
(top) and an element is removed from that end only.
Stack uses an encapsulated object of
either vector or deque (by default) or list (sequential container
class) as its underlying container, providing a specific set of
member functions to access its elements.
STL map
Maps are a part of the C++ STL. Maps are associative
containers that store elements in a combination of key values
and mapped values that follow a specific order. No two mapped
values can have the same key values.
STL map
STL map
STL map
CREDITS: This presentation template was created by Slidesgo,
including icons by Flaticon, and infographics & images by Freepik
Thank you

Data Strucure with STL

  • 1.
  • 2.
    Data Structures Every childknows that one can – at least beyond a certain number – find things much easier if one keeps order. We humans understand by keeping things in order that we separate the things that we possess into categories and assign fixed locations to these categories that we can remember. We may simply throw socks into a drawer, but for other things like DVDs it is best to sort them beyond a certain number so that we can quickly find every DVD.
  • 4.
    C++ STL STL standsfor Standard Template Library. Alexander Stepanov invented it in 1994, and later it was included in the standard library. The standard library consists of a set of algorithms and data structures that were originally part of the C++ Standard template library. STL helps in storing and manipulating objects, and it makes the program reusable and robust.
  • 5.
    CONTAINERS Suppose you areat your favorite cinema hall and it's the launch of a big movie. Since it's the launch, there are likely many people waiting in line to buy their tickets. Naturally, you join the queue at the back and wait for your turn. In the computing world, we have a queue too! This is a popular data structure. If you've had a Data Structures class before, you are most likely familiar with some other data structures as well. These are often used, so the STL provides a great implementation of all these data structures, otherwise known as containers.
  • 6.
    CONTAINERS Suppose you areat your favorite cinema hall and it's the launch of a big movie. Since it's the launch, there are likely many people waiting in line to buy their tickets. Naturally, you join the queue at the back and wait for your turn. In the computing world, we have a queue too! This is a popular data structure. If you've had a Data Structures class before, you are most likely familiar with some other data structures as well. These are often used, so the STL provides a great implementation of all these data structures, otherwise known as containers.
  • 7.
    CONTAINERS Suppose you areat your favorite cinema hall and it's the launch of a big movie. Since it's the launch, there are likely many people waiting in line to buy their tickets. Naturally, you join the queue at the back and wait for your turn. In the computing world, we have a queue too! This is a popular data structure. If you've had a Data Structures class before, you are most likely familiar with some other data structures as well. These are often used, so the STL provides a great implementation of all these data structures, otherwise known as containers.
  • 8.
    C++ STL STL standsfor Standard Template Library. Alexander Stepanov invented it in 1994, and later it was included in the standard library. The standard library consists of a set of algorithms and data structures that were originally part of the C++ Standard template library. STL helps in storing and manipulating objects, and it makes the program reusable and robust.
  • 9.
    Elements of theSTL - Containers - Collections of objects or primitive types - [Array, vector, deque, stack, set, map, etc] - Algorithms - Functions for processing sequences of elements from containers - [find, max, count, accumulate, sort, etc] - Iterators - Generate sequence of element from containers - [forward, reverse, by value, by reference, constant, etc.]
  • 10.
    CONTAINERS-ARRAYS But wait, STLprovides a container for arrays too. It's available in the header <array>. Example usage of it would look like this:
  • 11.
    CONTAINERS-ARRAYS But wait, STLprovides a container for arrays too. It's available in the header <array>. Example usage of it would look like this:
  • 12.
    CONTAINERS Take arrays, forexample. Arrays are elements with the same type, stored in contiguous blocks of memory. In C++, you can use arrays as you would in C, like this:
  • 13.
    CONTAINERS-ARRAYS Take arrays, forexample. Arrays are elements with the same type, stored in contiguous blocks of memory. In C++, you can use arrays as you would in C, like this:
  • 14.
    CONTAINERS-ARRAYS But wait, STLprovides a container for arrays too. It's available in the header <array>. Example usage of it would look like this:
  • 15.
    CONTAINERS-ARRAYS But wait, STLprovides a container for arrays too. It's available in the header <array>. Example usage of it would look like this:
  • 16.
  • 17.
    CONTAINERS-VECTORS Vector: Dynamically resizablearrays. Arrays have a set size, while std::vector doesn't. You can keep adding elements in contigious blocks of memory. For example:
  • 18.
    CONTAINERS-VECTORS Vector: Dynamically resizablearrays. Arrays have a set size, while std::vector doesn't. You can keep adding elements in contigious blocks of memory. For example:
  • 19.
    CONTAINERS-VECTORS Vectors are thesame as dynamic arrays with the ability to resize itself automatically when an element is inserted or deleted, with their storage being handled automatically by the container. Vector elements are placed in contiguous storage so that they can be accessed and traversed using iterators. In vectors, data is inserted at the end. Inserting at the end takes differential time, as sometimes the array may need to be extended. Removing the last element takes only constant time because no resizing happens. Inserting and erasing at the beginning or in the middle is linear in time.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
    CONTAINERS-DEQUE Deque in C++is an abbreviation that generally stands for double ended queue. The queue data structure is generalised by the Deque and that basically means the insertion and deletion can be executed from both the ends that can be either front or back.
  • 25.
    CONTAINERS-DEQUE Deque in C++is an abbreviation that generally stands for double ended queue. The queue data structure is generalised by the Deque and that basically means the insertion and deletion can be executed from both the ends that can be either front or back.
  • 26.
  • 27.
    CONTAINERS-DEQUE Deque in C++is an abbreviation that generally stands for double ended queue. The queue data structure is generalised by the Deque and that basically means the insertion and deletion can be executed from both the ends that can be either front or back.
  • 28.
    CONTAINERS-Forward list Forward listin STL implements singly linked list. Introduced from C++11, forward list are more useful than other containers in insertion, removal, and moving operations (like sort) and allow time constant insertion and removal of elements.
  • 29.
    CONTAINERS-Forward list Forward listin STL implements singly linked list. Introduced from C++11, forward list are more useful than other containers in insertion, removal, and moving operations (like sort) and allow time constant insertion and removal of elements.
  • 30.
    CONTAINERS-Forward list Forward listin STL implements singly linked list. Introduced from C++11, forward list are more useful than other containers in insertion, removal, and moving operations (like sort) and allow time constant insertion and removal of elements.
  • 31.
  • 32.
    New in c++ InC++ “new” is an operation that asks the underlying system to allocate memory to store something. Generally, that memory will be allocated in the system heap, but operator new can be overloaded to allocate memory in other locations (memory pools, custom memory arenas, etc.). The “something” is what you write after “new”. In your example: “int”.
  • 33.
    Arrow in c++ Differencebetween Dot(.) and Arrow(->) operator: The Dot(.) operator is used to normally access members of a structure or union. The Arrow(->) operator exists to access the members of the structure or the unions using pointers.
  • 34.
    Arrow in c++ Differencebetween Dot(.) and Arrow(->) operator: The Dot(.) operator is used to normally access members of a structure or union. The Arrow(->) operator exists to access the members of the structure or the unions using pointers.
  • 35.
    Doubly linked list Westrongly recommend to refer following post as a prerequisite of this post. Linked List Introduction Inserting a node in Singly Linked List A Doubly Linked List (DLL) contains an extra pointer, typically called previous pointer, together with next pointer and data which are there in singly linked list.
  • 36.
  • 37.
  • 39.
    Stack Stacks are atype of container adaptors with LIFO(Last In First Out) type of working, where a new element is added at one end (top) and an element is removed from that end only. Stack uses an encapsulated object of either vector or deque (by default) or list (sequential container class) as its underlying container, providing a specific set of member functions to access its elements.
  • 40.
    Stack Stacks are atype of container adaptors with LIFO(Last In First Out) type of working, where a new element is added at one end (top) and an element is removed from that end only. Stack uses an encapsulated object of either vector or deque (by default) or list (sequential container class) as its underlying container, providing a specific set of member functions to access its elements.
  • 41.
    STL map Maps area part of the C++ STL. Maps are associative containers that store elements in a combination of key values and mapped values that follow a specific order. No two mapped values can have the same key values.
  • 42.
  • 43.
  • 44.
  • 45.
    CREDITS: This presentationtemplate was created by Slidesgo, including icons by Flaticon, and infographics & images by Freepik Thank you