SlideShare una empresa de Scribd logo
1 de 33
STANDARD TEMPLATE 
LIBRARY 
BY: 
SUKRITI SINGH 
A0523113081 
BTBM/13/242 
AMITY INSTITUTE OF BIOTECHNOLOGY 
AMITY UNIVERSITY, NOIDA 
Teacher Incharge: 
Mr. Asit Dwivedi
Library 
Classes 
 To help programmers be more productive, 
C++ includes predefined classes in the form 
of packages as part of the installation. 
These are called ‘library classes.’ 
 It offers many packages through its 
libraries. Packages, in turn, provide 
thousands of classes that provides tens of 
thousands of methods for carrying out 
diverse type of tasks.
STANDARD TEMPLATE LIBRARY 
(STL) 
 T he C++ ST L (Standard Template Library) is a powerful set of C++ template 
classes to provide general-purpose templatized classes and functions that 
implement many popular and commonly used algorithms and data structures like 
vectors, lists, queues, and stacks. 
 Standard Template Library (STL) stands for standard template library and is 
basically a library of many useful containers or algorithms. 
 In layman terms , it basically is a class template with functions already created 
making life easier as they need to be merely called to be used. 
 The STL achieves its results through the use of templates. This approach is very 
powerful, delivering compile-time polymorphism that is often more efficient 
than traditional run-time polymorphism. Modern C++ compilers are tuned to 
minimize any abstraction penalty arising from heavy use of the STL.
The Standard Template Library was created as the first library of generic algorithms 
and data structures, with four ideas in mind: generic programming, abstractness 
without loss of efficiency, the Von Neumann computation model, and value semantics. 
The package file in C++ is stored in “namespace std” (namespace groups different 
identifiers in a named scope.), hence before using the library classes we need to call 
this directive as 
using namespace std; 
Function Objects 
Function Objects 
Iterators 
Algorithm Containers
Components 
of STL 
Containers 
Algorithms 
Iterators
Container is a way that stored data is organized in memory, for 
example an array of elements. 
Algorithms in the STL are procedures that are applied to 
containers to process their data, for example search for an 
element in an array, or sort an array. 
Iterators are a generalization of the concept of pointers, they 
point to elements in a container, for example you can 
increment an iterator to point to the next element in an array.
• Algorithm 
Sort, find, search, copy, … 
• Containers 
iterators 
vector, list, map, hash_map, … 
Each container has its own iterator types
Containers 
A container 
is a way to 
store data, 
either 
built-in 
data types 
like int and 
float, or 
class 
objects. 
Generic 
"off-the-shelf“ 
class 
templates 
for storing 
collections 
of data. 
Containers 
are used to 
manage 
collections 
of objects 
of a certain 
kind. 
There are 
several 
different 
types of 
containers 
like deque, 
list, vector, 
map etc.
Kinds of 
Containers 
Sequence 
• Store elements in linear sequence 
• Vectors, Linked Lists, and derivatives 
Adaptors 
• Used to automatically arrange stored 
data in a specific order. Uses trees 
• Queue, Priority_Queue, Stack 
Associative 
• Special purpose containers created 
from normal containers 
• Hash, Map, Set, Multimap, Multiset
Sequence 
Containers 
Special purpose containers created from normal 
containers.These containers store and retrieve data in a 
sequential fashion. 
A sequence container stores a set of elements in sequence, in 
other words each element (except for the first and last one) is 
preceded by one specific element and followed by another. 
In an ordinary C++ array the size is fixed and can not change 
during run-time, it is also tedious to insert or delete elements. 
Advantage: quick random access
Stores elements by 
position 
Each item in the list 
has both a value and a 
memory address 
(pointer) that 
identifies the next 
item in the sequence 
To access a specific 
data value in the list, 
one must start at the 
first position (front) 
and follow the 
pointers from element 
to element until data 
item is located. 
Basic Steps 
to Work in 
Sequence 
Containers
vector 
– dynamic array 
(hold sequences in difference ways) 
• Offers random but ‘direct’ access. 
• Back insertion 
• Should be your default choice, but choose wisely 
• Compatible with C : &v[0] points to the first element 
• Treated as an array with the capability of growing or shrinking 
dynamically. The elements can be accessed in two ways: 
i. using the overloaded operator ( ) 
ii. using the method at 
• The first one is easier and faster to use, but it is not range checked. 
• On the other hand, the method does range checking and throws 
out_of_range exception if needed.
deque 
– double-ended queue (usually array of arrays) 
o Offers random access 
o Back and Front insertion 
o Slower than vectors 
o No C - compatibility 
o This is basically a double-ended queue. 
o If we want to grow/shrink in a deque, we can do it at both the ends. 
o It provides the same accessing efficiency as the vector but the allocation efficiency 
comparable with a list.
list 
– 'traditional' doubly linked list 
 Don't expect random access 
 You can insert anywhere though, Arrays are optimised for random access 
but are inefficient when it comes to inserting and deleting elements in the 
middle; so are the vector and deque. 
 For operations requiring intensive insertions and deletions, use a list, which 
is very efficient for these operations (and is internally implemented as a 
double-linked list). 
 With a list, you cannot have random access to the data and so the operator 
is not overloaded.
Associative 
Containers 
• As the name suggest ‘Associate’ is linking it to 
different nodes. 
• Used to automatically arrange stored data in a 
specific order. Uses trees. 
• Tress provide and facilitates faster searching. 
• An associative container is non-sequential but uses a 
key to access elements. 
• The keys, typically a number or a string, are used by 
the container to arrange the stored elements in a 
specific order 
• for example in a dictionary the entries are ordered 
alphabetically.
Comparison of Trees, Lists, Arrays 
Trees : They are non-linear data structures, where a unique path exists to traverse(moving ahead or 
accessing) a particular node. Binary trees can utmost have 2 nodes, read either as Pre,In or Post. 
Node: It is a self referential data structure, which works on sending reference of its location to 
link of sets or maps. 
Link list: It is a serial collection of nodes. While this is a linear data structure. 
Array is a serial memory allocation while lists having serial nodes have a reference to the memory 
hence allocated randomly and linked to each other through references. 
Non-linear data 
structure engages 
memory in non 
sequential order. 
Linear data structures 
engages memory 
linearly or in a 
sequential order. 
Hence, we can 
conclude that
Maps: 
• Stores unique key/value pairs 
• key is associated with only one value (One-to-One 
Mapping). 
• Rapid key-based lookup. 
Sets: 
• Store the elements along with a unique key. 
• The values are irrelevant and we keep track of the 
keys only 
• Rapid lookup 
Common Points: 
• These two are interchangeable. 
• No duplicates 
• They provide an important functionality, 
Maps 
and 
Sets
3 
1 
0 2 5 
8 
7 
4 6
Multisets and Multimaps: 
These are extended versions of a map and set espectively. 
Multisets: 
• Stores non-unique sets 
• duplicates are allowed, Rapid lookup. 
Multimaps: 
• Stores non-unique key/value pairs 
• one key may be associated with more than one value (One-to-Many Mapping) 
• Duplicates are allowed 
• Rapid key based lookup
Adapter 
Containers 
Also known as Derived 
Containers. 
Provide different ways to 
access sequential & 
associative containers. 
They are implemented 
using the containers seen 
before 
They do not provide 
actual data structure 
Container adapters do 
not support iterators 
The functions push and 
pop are common to all 
container adapters 
component that adapts 
(modifies) an existing 
interface of a component 
to expose a different one 
suitable for some 
purpose. 
These containers restrict 
how elements enter and 
leave a sequence
Stack 
LIFO 
Last-in-first-out 
data 
structure 
They are 
implemented 
with vector, 
list, and deque 
(by default) 
Allows access 
at only one 
end of the 
sequence (top) 
Adds objects 
to container by 
pushing the 
object onto 
the stack 
Removes 
objects from 
container by 
popping the 
stack
Queue 
FIFO 
First in First 
Out Data 
Structure. 
Implemented 
with list and 
deque (by 
default). 
Allows access 
only at the 
front and 
rear of the 
sequence. 
Items enter 
at the rear 
and exit 
from the 
front. 
Example: 
waiting line 
at a grocery 
store.
Priority 
Queue 
• Insertions are done in a sorted order 
• Deletions from front similar to a queue 
• They are implemented with vector (by default) or deque 
• The elements with the highest priority are removed first 
• Operations are similar to those of a stack or queue 
• Elements can enter the priority queue in any order 
• Once in the container, a delete operation removes the largest (or 
smallest) value 
• Example: a filtering system that takes in elements and then releases 
them in priority order 
18 13 
3 15
In mathematics and Algorithm 
computer science, an 
algorithm is a step-by-step 
procedure. 
It is a specific set of 
instructions for carrying 
out a procedure or solving 
a problem 
Usually with the 
requirement that the 
procedure terminate at 
some point. 
Specific algorithms 
sometimes also go by the 
name method, procedure, 
or technique.
Algorithms typically take iterators as arguments 
Container provides a way to access its elements using 
iterators. 
Algorithms act on containers. 
Provide the means by which you will perform initialization, sorting 
, searching , and transforming of the contents of containers.
Iterators 
 Iterators are generalised pointers and act as the glue 
between containers and algorithms. 
 STL algorithms are written in terms of iterator 
parameters, and STL containers provide iterators that can 
be plugged into algorithms. 
 Generally, iterators point to a location within a container. 
 Iterators have a pointer-like syntax (in many cases, 
iterators are indeed implemented as pointers internally).
Iterators are used to step 
throug h the elements of 
collections of objects. 
These collections 
may be containers or 
subsets of containers. 
Iterators are pointer-like entities 
that are used to access individual 
elements in a container. 
Often they are used to move sequentially 
from element to element, a process 
called iterating through a container. 
One can have multiple iterators 
pointing to different or identical 
elements in the container
Container Type of iterator supported 
Sequence containers 
vector random access 
deque random access 
list bidirectional 
Associative containers 
set bidirectional 
multiset bidirectional 
map bidirectional 
multimap bidirectional 
Container adapters 
stack no iterators supported 
queue no iterators supported 
priority_queue 
no iterators supported
Compiling STL 
Container 
Algorithm 
Iterator 
Container 
Iterator 
Algorithm 
Objects 
Iterator 
Iterator 
Algorithm
Thank 
You!!!!

Más contenido relacionado

La actualidad más candente

String and string buffer
String and string bufferString and string buffer
String and string bufferkamal kotecha
 
Collection Framework in java
Collection Framework in javaCollection Framework in java
Collection Framework in javaCPD INDIA
 
Data Structures (CS8391)
Data Structures (CS8391)Data Structures (CS8391)
Data Structures (CS8391)Elavarasi K
 
Python Data Structures and Algorithms.pptx
Python Data Structures and Algorithms.pptxPython Data Structures and Algorithms.pptx
Python Data Structures and Algorithms.pptxShreyasLawand
 
ArrayList in JAVA
ArrayList in JAVAArrayList in JAVA
ArrayList in JAVASAGARDAVE29
 
Modules and packages in python
Modules and packages in pythonModules and packages in python
Modules and packages in pythonTMARAGATHAM
 
Arrays In Python | Python Array Operations | Edureka
Arrays In Python | Python Array Operations | EdurekaArrays In Python | Python Array Operations | Edureka
Arrays In Python | Python Array Operations | EdurekaEdureka!
 
5 collection framework
5 collection framework5 collection framework
5 collection frameworkMinal Maniar
 
Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]Muhammad Hammad Waseem
 
Java - Collections framework
Java - Collections frameworkJava - Collections framework
Java - Collections frameworkRiccardo Cardin
 
How to choose best containers in STL (C++)
How to choose best containers in STL (C++)How to choose best containers in STL (C++)
How to choose best containers in STL (C++)Sangharsh agarwal
 

La actualidad más candente (20)

String and string buffer
String and string bufferString and string buffer
String and string buffer
 
Vectors in Java
Vectors in JavaVectors in Java
Vectors in Java
 
Collection Framework in java
Collection Framework in javaCollection Framework in java
Collection Framework in java
 
Java Collections Framework
Java Collections FrameworkJava Collections Framework
Java Collections Framework
 
Data Structures (CS8391)
Data Structures (CS8391)Data Structures (CS8391)
Data Structures (CS8391)
 
Java Collections
Java  Collections Java  Collections
Java Collections
 
JAVA PROGRAMMING - The Collections Framework
JAVA PROGRAMMING - The Collections Framework JAVA PROGRAMMING - The Collections Framework
JAVA PROGRAMMING - The Collections Framework
 
Python Data Structures and Algorithms.pptx
Python Data Structures and Algorithms.pptxPython Data Structures and Algorithms.pptx
Python Data Structures and Algorithms.pptx
 
ArrayList in JAVA
ArrayList in JAVAArrayList in JAVA
ArrayList in JAVA
 
Wrapper classes
Wrapper classesWrapper classes
Wrapper classes
 
Modules and packages in python
Modules and packages in pythonModules and packages in python
Modules and packages in python
 
Arrays In Python | Python Array Operations | Edureka
Arrays In Python | Python Array Operations | EdurekaArrays In Python | Python Array Operations | Edureka
Arrays In Python | Python Array Operations | Edureka
 
Collections in Java Notes
Collections in Java NotesCollections in Java Notes
Collections in Java Notes
 
5 collection framework
5 collection framework5 collection framework
5 collection framework
 
Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]
 
Python programming : Classes objects
Python programming : Classes objectsPython programming : Classes objects
Python programming : Classes objects
 
Sets in python
Sets in pythonSets in python
Sets in python
 
Java - Collections framework
Java - Collections frameworkJava - Collections framework
Java - Collections framework
 
How to choose best containers in STL (C++)
How to choose best containers in STL (C++)How to choose best containers in STL (C++)
How to choose best containers in STL (C++)
 
Functions & Recursion
Functions & RecursionFunctions & Recursion
Functions & Recursion
 

Destacado

Algoritmi e Calcolo Parallelo 2012/2013 - Code di Priorita'
Algoritmi e Calcolo Parallelo 2012/2013 - Code di Priorita'Algoritmi e Calcolo Parallelo 2012/2013 - Code di Priorita'
Algoritmi e Calcolo Parallelo 2012/2013 - Code di Priorita'Pier Luca Lanzi
 
C++ Standard Template Library
C++ Standard Template LibraryC++ Standard Template Library
C++ Standard Template LibraryDuda Dornelles
 
An Introduction to Part of C++ STL
An Introduction to Part of C++ STLAn Introduction to Part of C++ STL
An Introduction to Part of C++ STL乐群 陈
 
Lecture11 standard template-library
Lecture11 standard template-libraryLecture11 standard template-library
Lecture11 standard template-libraryHariz Mustafa
 
Stl Containers
Stl ContainersStl Containers
Stl Containersppd1961
 
C++ Standard Template Library
C++ Standard Template LibraryC++ Standard Template Library
C++ Standard Template LibraryIlio Catallo
 

Destacado (7)

Algoritmi e Calcolo Parallelo 2012/2013 - Code di Priorita'
Algoritmi e Calcolo Parallelo 2012/2013 - Code di Priorita'Algoritmi e Calcolo Parallelo 2012/2013 - Code di Priorita'
Algoritmi e Calcolo Parallelo 2012/2013 - Code di Priorita'
 
C++ Standard Template Library
C++ Standard Template LibraryC++ Standard Template Library
C++ Standard Template Library
 
C++ STL 概觀
C++ STL 概觀C++ STL 概觀
C++ STL 概觀
 
An Introduction to Part of C++ STL
An Introduction to Part of C++ STLAn Introduction to Part of C++ STL
An Introduction to Part of C++ STL
 
Lecture11 standard template-library
Lecture11 standard template-libraryLecture11 standard template-library
Lecture11 standard template-library
 
Stl Containers
Stl ContainersStl Containers
Stl Containers
 
C++ Standard Template Library
C++ Standard Template LibraryC++ Standard Template Library
C++ Standard Template Library
 

Similar a Standard Template Library (STL

DS Module1 (1).pptx
DS Module1 (1).pptxDS Module1 (1).pptx
DS Module1 (1).pptxAnuJoseph95
 
Unit 2 linear data structures
Unit 2   linear data structuresUnit 2   linear data structures
Unit 2 linear data structuresSenthil Murugan
 
Data Structure & Algorithm.pptx
Data Structure & Algorithm.pptxData Structure & Algorithm.pptx
Data Structure & Algorithm.pptxMumtaz
 
linked_list.pdf [for undergraduate students
linked_list.pdf [for undergraduate studentslinked_list.pdf [for undergraduate students
linked_list.pdf [for undergraduate studentsSazzadulIslam42
 
Data_structure.pptx
Data_structure.pptxData_structure.pptx
Data_structure.pptxpriya415376
 
DS Module 1.pptx
DS Module 1.pptxDS Module 1.pptx
DS Module 1.pptxSaralaT3
 
DS Module 1.pptx
DS Module 1.pptxDS Module 1.pptx
DS Module 1.pptxsarala9
 
Data structures - unit 1
Data structures - unit 1Data structures - unit 1
Data structures - unit 1SaranyaP45
 
358 33 powerpoint-slides_4-introduction-data-structures_chapter-4
358 33 powerpoint-slides_4-introduction-data-structures_chapter-4358 33 powerpoint-slides_4-introduction-data-structures_chapter-4
358 33 powerpoint-slides_4-introduction-data-structures_chapter-4sumitbardhan
 
Learn advanced java programming
Learn advanced java programmingLearn advanced java programming
Learn advanced java programmingTOPS Technologies
 

Similar a Standard Template Library (STL (20)

DS Module1 (1).pptx
DS Module1 (1).pptxDS Module1 (1).pptx
DS Module1 (1).pptx
 
Standard template library
Standard template libraryStandard template library
Standard template library
 
data science
data sciencedata science
data science
 
Unit 2 linear data structures
Unit 2   linear data structuresUnit 2   linear data structures
Unit 2 linear data structures
 
Data Structure & Algorithm.pptx
Data Structure & Algorithm.pptxData Structure & Algorithm.pptx
Data Structure & Algorithm.pptx
 
linked_list.pdf [for undergraduate students
linked_list.pdf [for undergraduate studentslinked_list.pdf [for undergraduate students
linked_list.pdf [for undergraduate students
 
oops_final_ppt[1].pptx
oops_final_ppt[1].pptxoops_final_ppt[1].pptx
oops_final_ppt[1].pptx
 
lecture 02.2.ppt
lecture 02.2.pptlecture 02.2.ppt
lecture 02.2.ppt
 
Data_structure.pptx
Data_structure.pptxData_structure.pptx
Data_structure.pptx
 
Collections Training
Collections TrainingCollections Training
Collections Training
 
DS Module 1.pptx
DS Module 1.pptxDS Module 1.pptx
DS Module 1.pptx
 
DS Module 1.pptx
DS Module 1.pptxDS Module 1.pptx
DS Module 1.pptx
 
The Standard Template Library
The Standard Template LibraryThe Standard Template Library
The Standard Template Library
 
Data structures - unit 1
Data structures - unit 1Data structures - unit 1
Data structures - unit 1
 
stack.pptx
stack.pptxstack.pptx
stack.pptx
 
Javasession7
Javasession7Javasession7
Javasession7
 
Data structures in c#
Data structures in c#Data structures in c#
Data structures in c#
 
TSAT Presentation1.pptx
TSAT Presentation1.pptxTSAT Presentation1.pptx
TSAT Presentation1.pptx
 
358 33 powerpoint-slides_4-introduction-data-structures_chapter-4
358 33 powerpoint-slides_4-introduction-data-structures_chapter-4358 33 powerpoint-slides_4-introduction-data-structures_chapter-4
358 33 powerpoint-slides_4-introduction-data-structures_chapter-4
 
Learn advanced java programming
Learn advanced java programmingLearn advanced java programming
Learn advanced java programming
 

Más de Sukriti Singh

The duchess and the jeweler
The duchess and the jewelerThe duchess and the jeweler
The duchess and the jewelerSukriti Singh
 
Reading and listening comprehension
Reading and listening comprehensionReading and listening comprehension
Reading and listening comprehensionSukriti Singh
 
Patents and case study
Patents and case study Patents and case study
Patents and case study Sukriti Singh
 
Immobilisation cell culture
Immobilisation cell cultureImmobilisation cell culture
Immobilisation cell cultureSukriti Singh
 
Hydrogels assignment 2
Hydrogels assignment 2Hydrogels assignment 2
Hydrogels assignment 2Sukriti Singh
 
Grapevine communication
Grapevine communicationGrapevine communication
Grapevine communicationSukriti Singh
 
Effect of cosmetics pptx
Effect of cosmetics pptxEffect of cosmetics pptx
Effect of cosmetics pptxSukriti Singh
 
Design and development of data collection
Design and development of data collectionDesign and development of data collection
Design and development of data collectionSukriti Singh
 
Cancer Chemoprevention and Molecular Targeting Drug Delivery for Cancer
Cancer Chemoprevention and Molecular Targeting Drug Delivery for CancerCancer Chemoprevention and Molecular Targeting Drug Delivery for Cancer
Cancer Chemoprevention and Molecular Targeting Drug Delivery for CancerSukriti Singh
 
Bioterrorism and drug prepardness
Bioterrorism and drug prepardnessBioterrorism and drug prepardness
Bioterrorism and drug prepardnessSukriti Singh
 
Artistic freedom – should there be limits
Artistic freedom – should there be limitsArtistic freedom – should there be limits
Artistic freedom – should there be limitsSukriti Singh
 
The Proof of the Pudding
The Proof of the PuddingThe Proof of the Pudding
The Proof of the PuddingSukriti Singh
 
Web based writing - English Asignment
Web based writing - English AsignmentWeb based writing - English Asignment
Web based writing - English AsignmentSukriti Singh
 

Más de Sukriti Singh (20)

The duchess and the jeweler
The duchess and the jewelerThe duchess and the jeweler
The duchess and the jeweler
 
Demonetisation
DemonetisationDemonetisation
Demonetisation
 
Reading and listening comprehension
Reading and listening comprehensionReading and listening comprehension
Reading and listening comprehension
 
Patents and case study
Patents and case study Patents and case study
Patents and case study
 
Immobilisation cell culture
Immobilisation cell cultureImmobilisation cell culture
Immobilisation cell culture
 
Hydrogels assignment 2
Hydrogels assignment 2Hydrogels assignment 2
Hydrogels assignment 2
 
Grapevine communication
Grapevine communicationGrapevine communication
Grapevine communication
 
Good governance
Good governanceGood governance
Good governance
 
Gas chromatography
Gas chromatographyGas chromatography
Gas chromatography
 
Epidemiology
EpidemiologyEpidemiology
Epidemiology
 
Effect of cosmetics pptx
Effect of cosmetics pptxEffect of cosmetics pptx
Effect of cosmetics pptx
 
Design and development of data collection
Design and development of data collectionDesign and development of data collection
Design and development of data collection
 
Cancer Chemoprevention and Molecular Targeting Drug Delivery for Cancer
Cancer Chemoprevention and Molecular Targeting Drug Delivery for CancerCancer Chemoprevention and Molecular Targeting Drug Delivery for Cancer
Cancer Chemoprevention and Molecular Targeting Drug Delivery for Cancer
 
Bioterrorism and drug prepardness
Bioterrorism and drug prepardnessBioterrorism and drug prepardness
Bioterrorism and drug prepardness
 
Biofuels
BiofuelsBiofuels
Biofuels
 
Artistic freedom – should there be limits
Artistic freedom – should there be limitsArtistic freedom – should there be limits
Artistic freedom – should there be limits
 
The Proof of the Pudding
The Proof of the PuddingThe Proof of the Pudding
The Proof of the Pudding
 
Web based writing - English Asignment
Web based writing - English AsignmentWeb based writing - English Asignment
Web based writing - English Asignment
 
Good governance
Good governanceGood governance
Good governance
 
Punctuations
PunctuationsPunctuations
Punctuations
 

Último

A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 

Último (20)

A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 

Standard Template Library (STL

  • 1. STANDARD TEMPLATE LIBRARY BY: SUKRITI SINGH A0523113081 BTBM/13/242 AMITY INSTITUTE OF BIOTECHNOLOGY AMITY UNIVERSITY, NOIDA Teacher Incharge: Mr. Asit Dwivedi
  • 2. Library Classes  To help programmers be more productive, C++ includes predefined classes in the form of packages as part of the installation. These are called ‘library classes.’  It offers many packages through its libraries. Packages, in turn, provide thousands of classes that provides tens of thousands of methods for carrying out diverse type of tasks.
  • 3. STANDARD TEMPLATE LIBRARY (STL)  T he C++ ST L (Standard Template Library) is a powerful set of C++ template classes to provide general-purpose templatized classes and functions that implement many popular and commonly used algorithms and data structures like vectors, lists, queues, and stacks.  Standard Template Library (STL) stands for standard template library and is basically a library of many useful containers or algorithms.  In layman terms , it basically is a class template with functions already created making life easier as they need to be merely called to be used.  The STL achieves its results through the use of templates. This approach is very powerful, delivering compile-time polymorphism that is often more efficient than traditional run-time polymorphism. Modern C++ compilers are tuned to minimize any abstraction penalty arising from heavy use of the STL.
  • 4. The Standard Template Library was created as the first library of generic algorithms and data structures, with four ideas in mind: generic programming, abstractness without loss of efficiency, the Von Neumann computation model, and value semantics. The package file in C++ is stored in “namespace std” (namespace groups different identifiers in a named scope.), hence before using the library classes we need to call this directive as using namespace std; Function Objects Function Objects Iterators Algorithm Containers
  • 5. Components of STL Containers Algorithms Iterators
  • 6. Container is a way that stored data is organized in memory, for example an array of elements. Algorithms in the STL are procedures that are applied to containers to process their data, for example search for an element in an array, or sort an array. Iterators are a generalization of the concept of pointers, they point to elements in a container, for example you can increment an iterator to point to the next element in an array.
  • 7. • Algorithm Sort, find, search, copy, … • Containers iterators vector, list, map, hash_map, … Each container has its own iterator types
  • 8. Containers A container is a way to store data, either built-in data types like int and float, or class objects. Generic "off-the-shelf“ class templates for storing collections of data. Containers are used to manage collections of objects of a certain kind. There are several different types of containers like deque, list, vector, map etc.
  • 9. Kinds of Containers Sequence • Store elements in linear sequence • Vectors, Linked Lists, and derivatives Adaptors • Used to automatically arrange stored data in a specific order. Uses trees • Queue, Priority_Queue, Stack Associative • Special purpose containers created from normal containers • Hash, Map, Set, Multimap, Multiset
  • 10. Sequence Containers Special purpose containers created from normal containers.These containers store and retrieve data in a sequential fashion. A sequence container stores a set of elements in sequence, in other words each element (except for the first and last one) is preceded by one specific element and followed by another. In an ordinary C++ array the size is fixed and can not change during run-time, it is also tedious to insert or delete elements. Advantage: quick random access
  • 11.
  • 12. Stores elements by position Each item in the list has both a value and a memory address (pointer) that identifies the next item in the sequence To access a specific data value in the list, one must start at the first position (front) and follow the pointers from element to element until data item is located. Basic Steps to Work in Sequence Containers
  • 13. vector – dynamic array (hold sequences in difference ways) • Offers random but ‘direct’ access. • Back insertion • Should be your default choice, but choose wisely • Compatible with C : &v[0] points to the first element • Treated as an array with the capability of growing or shrinking dynamically. The elements can be accessed in two ways: i. using the overloaded operator ( ) ii. using the method at • The first one is easier and faster to use, but it is not range checked. • On the other hand, the method does range checking and throws out_of_range exception if needed.
  • 14. deque – double-ended queue (usually array of arrays) o Offers random access o Back and Front insertion o Slower than vectors o No C - compatibility o This is basically a double-ended queue. o If we want to grow/shrink in a deque, we can do it at both the ends. o It provides the same accessing efficiency as the vector but the allocation efficiency comparable with a list.
  • 15. list – 'traditional' doubly linked list  Don't expect random access  You can insert anywhere though, Arrays are optimised for random access but are inefficient when it comes to inserting and deleting elements in the middle; so are the vector and deque.  For operations requiring intensive insertions and deletions, use a list, which is very efficient for these operations (and is internally implemented as a double-linked list).  With a list, you cannot have random access to the data and so the operator is not overloaded.
  • 16. Associative Containers • As the name suggest ‘Associate’ is linking it to different nodes. • Used to automatically arrange stored data in a specific order. Uses trees. • Tress provide and facilitates faster searching. • An associative container is non-sequential but uses a key to access elements. • The keys, typically a number or a string, are used by the container to arrange the stored elements in a specific order • for example in a dictionary the entries are ordered alphabetically.
  • 17. Comparison of Trees, Lists, Arrays Trees : They are non-linear data structures, where a unique path exists to traverse(moving ahead or accessing) a particular node. Binary trees can utmost have 2 nodes, read either as Pre,In or Post. Node: It is a self referential data structure, which works on sending reference of its location to link of sets or maps. Link list: It is a serial collection of nodes. While this is a linear data structure. Array is a serial memory allocation while lists having serial nodes have a reference to the memory hence allocated randomly and linked to each other through references. Non-linear data structure engages memory in non sequential order. Linear data structures engages memory linearly or in a sequential order. Hence, we can conclude that
  • 18.
  • 19. Maps: • Stores unique key/value pairs • key is associated with only one value (One-to-One Mapping). • Rapid key-based lookup. Sets: • Store the elements along with a unique key. • The values are irrelevant and we keep track of the keys only • Rapid lookup Common Points: • These two are interchangeable. • No duplicates • They provide an important functionality, Maps and Sets
  • 20. 3 1 0 2 5 8 7 4 6
  • 21. Multisets and Multimaps: These are extended versions of a map and set espectively. Multisets: • Stores non-unique sets • duplicates are allowed, Rapid lookup. Multimaps: • Stores non-unique key/value pairs • one key may be associated with more than one value (One-to-Many Mapping) • Duplicates are allowed • Rapid key based lookup
  • 22. Adapter Containers Also known as Derived Containers. Provide different ways to access sequential & associative containers. They are implemented using the containers seen before They do not provide actual data structure Container adapters do not support iterators The functions push and pop are common to all container adapters component that adapts (modifies) an existing interface of a component to expose a different one suitable for some purpose. These containers restrict how elements enter and leave a sequence
  • 23.
  • 24. Stack LIFO Last-in-first-out data structure They are implemented with vector, list, and deque (by default) Allows access at only one end of the sequence (top) Adds objects to container by pushing the object onto the stack Removes objects from container by popping the stack
  • 25. Queue FIFO First in First Out Data Structure. Implemented with list and deque (by default). Allows access only at the front and rear of the sequence. Items enter at the rear and exit from the front. Example: waiting line at a grocery store.
  • 26. Priority Queue • Insertions are done in a sorted order • Deletions from front similar to a queue • They are implemented with vector (by default) or deque • The elements with the highest priority are removed first • Operations are similar to those of a stack or queue • Elements can enter the priority queue in any order • Once in the container, a delete operation removes the largest (or smallest) value • Example: a filtering system that takes in elements and then releases them in priority order 18 13 3 15
  • 27. In mathematics and Algorithm computer science, an algorithm is a step-by-step procedure. It is a specific set of instructions for carrying out a procedure or solving a problem Usually with the requirement that the procedure terminate at some point. Specific algorithms sometimes also go by the name method, procedure, or technique.
  • 28. Algorithms typically take iterators as arguments Container provides a way to access its elements using iterators. Algorithms act on containers. Provide the means by which you will perform initialization, sorting , searching , and transforming of the contents of containers.
  • 29. Iterators  Iterators are generalised pointers and act as the glue between containers and algorithms.  STL algorithms are written in terms of iterator parameters, and STL containers provide iterators that can be plugged into algorithms.  Generally, iterators point to a location within a container.  Iterators have a pointer-like syntax (in many cases, iterators are indeed implemented as pointers internally).
  • 30. Iterators are used to step throug h the elements of collections of objects. These collections may be containers or subsets of containers. Iterators are pointer-like entities that are used to access individual elements in a container. Often they are used to move sequentially from element to element, a process called iterating through a container. One can have multiple iterators pointing to different or identical elements in the container
  • 31. Container Type of iterator supported Sequence containers vector random access deque random access list bidirectional Associative containers set bidirectional multiset bidirectional map bidirectional multimap bidirectional Container adapters stack no iterators supported queue no iterators supported priority_queue no iterators supported
  • 32. Compiling STL Container Algorithm Iterator Container Iterator Algorithm Objects Iterator Iterator Algorithm

Notas del editor

  1. Generic programming: is a style of computer programming in which algorithms are written in terms of to-be-specified-later types that are then instantiated when needed for specific types provided as parameters.