SlideShare a Scribd company logo
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
1
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
2
 Abstract data type (ADT) implementation in C++
and rationale for using them
 How ADTs aid code reuse
 Five components of standard template library
(STL) and their power
 Simplify task of writing application codes with
the use of STL
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
3
 The STL is a part of the standard C++ class library
and can be used as the standard approach for
storing and processing data
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
4
 A data type consists of a collection of values
together with a set of basic operations defined
on these values
 A data type is called an ADT if a programmer can
use it without having access to and also without
knowing the details of how the values and
operations are implemented
Abstract Data Type
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
5
 The term ADT describes a comprehensive
collection of data values and operations
 The term data structure refers to the study of
data and how to represent data object within a
program, that is, the implementation of
structured relationship
Abstract Data Type and Data
Structures
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
6
 ADT stack(element)
 Declare create() → stack
 pop(push(e,S)) = S
 getTop(stack) → element
 is_empty(stack) → Boolean;
 is_empty(create) = true
 pop(stack) → stack
 for all S Î stack, e Î element,
is_empty(push(e, S)) = false
 pop(create()) = error
 push(element, stack) → stack
Stack Abstract Data Type
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
7
A Survey of Programming
Object-oriented Programming
Techniques
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
8
Unstructured programming
Procedural programming
Modular programming
Object-oriented programming
A Survey of Programming
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
9
 Unstructured programming: the main program
directly operates on global data
Unstructured programming
Program
PROGRAM
MAIN PROGRAM DATA
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
10
 With procedural programming, we are able to
combine returning sequences of statements into
one single place
 A procedure call is used to invoke the procedure
Procedural Programming
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
11
 Execution of procedures: after processing,
flow of controls proceed where the call was made
Procedural Programming
Main program Procedure
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
12
Procedural programming: the main program coordinates calls to
procedures and hands over appropriate data as parameters
Procedural Programming
Program
PROGRAM
MAIN PROGRAM
DATA
PROCEDURE1 PROCEDUR
E2
PROCEDUR
E3
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
13
Modular
programming
Program
Main program
data
Module1
data+da
ta1
Module2
data+dat2
Procedure1 Procedure2 Procedure3
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
14
Object-oriented programming: objects of the program interact by
sending messages to each other
Object-oriented Programming
Program
Object1
data
Object4
data
Object
3 data
Object2
data
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
15
Object-oriented programming is a method of
implementation in which
 Objects are the fundamental building blocks
 Each object is an instance of some type (specification
or class)
 Objects can interact with each other
 Classes are related to each other by inheritance
relationship
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
16
 An object-oriented language is the one that supports
objects, and programs divided into objects,
 contains objects belonging to a class,
 supports inheritance
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
17
 Objects
 Classes
 Data abstraction and encapsulation
 Inheritance
 Reusability
 Polymerisation
 Dynamic binding
 Message passing
Basic Concepts of Object-oriented
Programming
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
18
Objects
 Objects are the basic runtime entities in an object-
oriented system
 Programming problem is analyzed in terms of objects
and the nature of communication between them
 Each object contains data and code to manipulate the
data
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
19
 Object-oriented programming encapsulates data
(attributes) and functions (behaviour) into package called
as classes
 A class is a user-defined data type
Classes
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
20
 Encapsulation : Combining a number of variables and
functions into a single package
 Abstraction : It refers to the act of representing
essential features without including the details of
implementation
 Generally, data members are made private and are
accessible to only class member functions
 This insulation of data from direct access by the
program is called data hiding or information hiding
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
21
 Inheritance is a process by which the objects of one
class inherit the properties of another class
 Classes in C++ support the concept of hierarchical
classification
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
22
 The concept of inheritance providing feature of
reusability by additional features to the existing class
without modifying the existing one leads to a new
class
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
23
 Polymorphism means the ability to take more than
one form
 Polymorphism is a mean by which we can request an
object to do something without knowing exactly
what kind of object it is, and the object will figure out
how to process the request appropriately
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
24
 Binding refers to the linking of a procedure call to the code
to be executed in response to the call
 Dynamic binding means that the code associated with a given
procedure call is not known until the time of call at runtime
 This is associated with polymorphism and inheritance
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
25
 An OOP consists of a set of objects that communicate with each
other
 Message for an object is a request for execution of a procedure
and therefore will invoke a function in the receiving object that
generates the desired result
 Message passing involves specifying the name of the object, the
name of the function (message), and the information to be sent
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
26
 A class template is a generic class declaration that allows the
user to provide the data structure through parameters that the
compiler resolved
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
27
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
28
Abstract representation of linked list
Linked list with header pointer
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
29
 The C++ STL is a collection of
 Containers
 Iterators
 Algorithms
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
30
 The STL is a part of the standard C++ class library and can be
used as a standard approach for storing and processing data
 The task of writing complex application codes can be made easy
with the use of STL
 The STL allows programmer to use these classes and functions
directly in programs to increase productivity
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
31
Container class contains other objects. Container is a way to store
data, whether the data consists of built-in types such as int and float,
or of class objects
Container class Description
 Vector Array
 List Doubly linked list
 Slist Singly linked list
 Queue Queue structure, that is, FIFO structure
 Stack Stack structure, that is, LIFO structure
 Deque Combination of stack and queue, having
 facility for insertion and removal from both
ends
 Set Set of unique elements
 Map Store key and data pair
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
32
Containers are categorized into two types:
 Sequence containers
 Associative containers
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
33
The sequence containers are as follows:
 Vectors
Lists
Deques

The containers that are derived from sequence
containers are as follows:
 Stacks
 Queues
 Priority queues

Sequence containers
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
34
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
35
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
36
List of containers and their
characteristics
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
37
Associative Containers
 An associative container is a collection of stored objects
that allow fast retrieval using a key
 In each container, the key must be unique
 There are four standard associative containers classified
into two classes:
 Sets
 (a) Set
 (b) Multiset
 Maps
 (a) Map
 (b) Multimap list
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
38
 The header <algorithm> defines a collection of
functions especially designed to be used on
ranges of elements
 These algorithms can be divided into six groups:
 Minimum and maximum algorithm
 Numeric algorithms
 Non-mutating sequence algorithms
 Sorting algorithm
 Set operations on sorted sequence
 Heap operations
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
39
 Suppose we create an array of type int storing
marks of the student
 Then, int marks [6] = {73, 44, 42, 51, 59, 50}
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
40
 We can use STL sort() assort(marks, marks + 6)
 Here, marks is the start and marks + 6 is the end
addresses, respectively
 Other example of sorting vector is as follows:
vector<int> m;
/having values 73, 44, 42, 51, 59, 50
sort(m.begin(), m.end() );
// Output is 42, 44, 50, 51, 59, 73
sort(v.begin(), v.end(), greater<int>());
// Output is 73, 59, 51, 50, 44, 42
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
41
 replace() Replace value in range
 fill() Fill range with value
 remove() Remove value from range
 reverse() Reverse range
 sort() Sort elements in range
 partial_sort() Partially sort elements in range
 nth_element() Sort element in range
 binary_search() Test if value exists in sorted arra
 merge() Merge sorted ranges
 min() Return the lesser of two arguments
 max() Return the greater of two arguments
 Min_element() Return the smallest element in range
 max_element() Return the largest element in range
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
42
Iterator—Iterator is pointer like entity, which
is used to access individual data items in a
container, and it is used to store and retrieve
objects in C++
STL defines five different iterators
 Forward
 Bidirectional
 Random access
 Input iterator
 Output iterator
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
43
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
44
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
45
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
46
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
47
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
48
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
49
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
50

More Related Content

PPTX
12. Heaps - Data Structures using C++ by Varsha Patil
PPTX
6. Linked list - Data Structures using C++ by Varsha Patil
PPTX
14. Files - Data Structures using C++ by Varsha Patil
PPTX
5. Queue - Data Structures using C++ by Varsha Patil
PPTX
3. Stack - Data Structures using C++ by Varsha Patil
PPTX
9. Searching & Sorting - Data Structures using C++ by Varsha Patil
PPTX
1. Fundamental Concept - Data Structures using C++ by Varsha Patil
PPTX
10. Search Tree - Data Structures using C++ by Varsha Patil
12. Heaps - Data Structures using C++ by Varsha Patil
6. Linked list - Data Structures using C++ by Varsha Patil
14. Files - Data Structures using C++ by Varsha Patil
5. Queue - Data Structures using C++ by Varsha Patil
3. Stack - Data Structures using C++ by Varsha Patil
9. Searching & Sorting - Data Structures using C++ by Varsha Patil
1. Fundamental Concept - Data Structures using C++ by Varsha Patil
10. Search Tree - Data Structures using C++ by Varsha Patil

What's hot (20)

PPTX
13. Indexing MTrees - Data Structures using C++ by Varsha Patil
PPTX
16. Algo analysis & Design - Data Structures using C++ by Varsha Patil
PPTX
7. Tree - Data Structures using C++ by Varsha Patil
PPTX
4. Recursion - Data Structures using C++ by Varsha Patil
PPTX
11. Hashing - Data Structures using C++ by Varsha Patil
PPTX
8. Graph - Data Structures using C++ by Varsha Patil
PDF
Lecture 07 Data Structures - Basic Sorting
PDF
indexing and hashing
PDF
Ii pu cs practical viva voce questions
PDF
Z04506138145
PDF
DSA - Lecture 04
PPT
Chapter 8: tree data structure
PDF
Lecture 9 - DSA - Python Data Structures
PPTX
Data Structures
PPTX
ChemExtractor: Enhanced Rule-Based Capture and Identification of PDF Based Pr...
PPTX
Development of a new indexing technique for XML document retrieval
PDF
Mapping Domain Names to Categories
PDF
linked_lists
PPTX
Presentation on data preparation with pandas
13. Indexing MTrees - Data Structures using C++ by Varsha Patil
16. Algo analysis & Design - Data Structures using C++ by Varsha Patil
7. Tree - Data Structures using C++ by Varsha Patil
4. Recursion - Data Structures using C++ by Varsha Patil
11. Hashing - Data Structures using C++ by Varsha Patil
8. Graph - Data Structures using C++ by Varsha Patil
Lecture 07 Data Structures - Basic Sorting
indexing and hashing
Ii pu cs practical viva voce questions
Z04506138145
DSA - Lecture 04
Chapter 8: tree data structure
Lecture 9 - DSA - Python Data Structures
Data Structures
ChemExtractor: Enhanced Rule-Based Capture and Identification of PDF Based Pr...
Development of a new indexing technique for XML document retrieval
Mapping Domain Names to Categories
linked_lists
Presentation on data preparation with pandas
Ad

Viewers also liked (18)

PDF
Discrete Mathematics S. Lipschutz, M. Lipson And V. H. Patil
PPTX
Pointers in c++
PPTX
Array,lists and hashes in perl
PPTX
Lists, queues and stacks
PPTX
Classes and objects1
PPTX
Constructors and destructors
PPTX
Structured query language functions
DOCX
Advanced data structures using c++ 3
PPTX
Structured query language constraints
PPS
PDF
Working with Cookies in NodeJS
PPTX
Stacks in c++
PPTX
Data types in c++
PPT
C++ data types
PPS
Data Structure
PPTX
Data file handling in c++
PPT
Stacks in algorithems & data structure
PPT
stacks in algorithems and data structure
Discrete Mathematics S. Lipschutz, M. Lipson And V. H. Patil
Pointers in c++
Array,lists and hashes in perl
Lists, queues and stacks
Classes and objects1
Constructors and destructors
Structured query language functions
Advanced data structures using c++ 3
Structured query language constraints
Working with Cookies in NodeJS
Stacks in c++
Data types in c++
C++ data types
Data Structure
Data file handling in c++
Stacks in algorithems & data structure
stacks in algorithems and data structure
Ad

Similar to 15. STL - Data Structures using C++ by Varsha Patil (20)

DOCX
Cs6301 programming and datastactures
PPTX
OODP Unit 1 OOPs classes and objects
PPTX
Introduction to datastructures presentation
PDF
C++
PPTX
Object Oriented Programming using C++ - OOPS concepts using C++ programming l...
PPTX
Unit - I Fundamentals of Object Oriented Programming .pptx
PPT
Oop lec 3(structures)
PPTX
DSD Unit 1 Abstract Data Type data structures design notes.pptx
PPTX
DS 2024 Lecturde dcdcdcdcdcdcd3 & 4.pptx
PDF
C++ [ principles of object oriented programming ]
PPT
01_intro-cpp.ppt
PPT
01_intro-cpp.ppt
PPT
Introduction to data structure and algorithm
PPT
01_intro-cpjgknkhjgjv hugbbf vjouhghp.ppt
PPTX
Chapter - 1.pptx
PPTX
Introduction to C++
PPT
9780324782011_PPT_ch09.ppt
PPTX
1.1-Introduction to Object oriented.pptx
Cs6301 programming and datastactures
OODP Unit 1 OOPs classes and objects
Introduction to datastructures presentation
C++
Object Oriented Programming using C++ - OOPS concepts using C++ programming l...
Unit - I Fundamentals of Object Oriented Programming .pptx
Oop lec 3(structures)
DSD Unit 1 Abstract Data Type data structures design notes.pptx
DS 2024 Lecturde dcdcdcdcdcdcd3 & 4.pptx
C++ [ principles of object oriented programming ]
01_intro-cpp.ppt
01_intro-cpp.ppt
Introduction to data structure and algorithm
01_intro-cpjgknkhjgjv hugbbf vjouhghp.ppt
Chapter - 1.pptx
Introduction to C++
9780324782011_PPT_ch09.ppt
1.1-Introduction to Object oriented.pptx

Recently uploaded (20)

PPT
Miokarditis (Inflamasi pada Otot Jantung)
PDF
“Getting Started with Data Analytics Using R – Concepts, Tools & Case Studies”
PPTX
Introduction to Knowledge Engineering Part 1
PDF
.pdf is not working space design for the following data for the following dat...
PPTX
01_intro xxxxxxxxxxfffffffffffaaaaaaaaaaafg
PPTX
Introduction to Firewall Analytics - Interfirewall and Transfirewall.pptx
PPT
ISS -ESG Data flows What is ESG and HowHow
PDF
22.Patil - Early prediction of Alzheimer’s disease using convolutional neural...
PPTX
IB Computer Science - Internal Assessment.pptx
PDF
Foundation of Data Science unit number two notes
PPTX
Introduction to machine learning and Linear Models
PDF
Mega Projects Data Mega Projects Data
PPTX
1_Introduction to advance data techniques.pptx
PPTX
Introduction to Basics of Ethical Hacking and Penetration Testing -Unit No. 1...
PPTX
Computer network topology notes for revision
PPTX
Introduction-to-Cloud-ComputingFinal.pptx
PPTX
oil_refinery_comprehensive_20250804084928 (1).pptx
PPT
Quality review (1)_presentation of this 21
PPTX
Qualitative Qantitative and Mixed Methods.pptx
PDF
Lecture1 pattern recognition............
Miokarditis (Inflamasi pada Otot Jantung)
“Getting Started with Data Analytics Using R – Concepts, Tools & Case Studies”
Introduction to Knowledge Engineering Part 1
.pdf is not working space design for the following data for the following dat...
01_intro xxxxxxxxxxfffffffffffaaaaaaaaaaafg
Introduction to Firewall Analytics - Interfirewall and Transfirewall.pptx
ISS -ESG Data flows What is ESG and HowHow
22.Patil - Early prediction of Alzheimer’s disease using convolutional neural...
IB Computer Science - Internal Assessment.pptx
Foundation of Data Science unit number two notes
Introduction to machine learning and Linear Models
Mega Projects Data Mega Projects Data
1_Introduction to advance data techniques.pptx
Introduction to Basics of Ethical Hacking and Penetration Testing -Unit No. 1...
Computer network topology notes for revision
Introduction-to-Cloud-ComputingFinal.pptx
oil_refinery_comprehensive_20250804084928 (1).pptx
Quality review (1)_presentation of this 21
Qualitative Qantitative and Mixed Methods.pptx
Lecture1 pattern recognition............

15. STL - Data Structures using C++ by Varsha Patil

  • 1. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 1
  • 2. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 2  Abstract data type (ADT) implementation in C++ and rationale for using them  How ADTs aid code reuse  Five components of standard template library (STL) and their power  Simplify task of writing application codes with the use of STL
  • 3. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 3  The STL is a part of the standard C++ class library and can be used as the standard approach for storing and processing data
  • 4. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 4  A data type consists of a collection of values together with a set of basic operations defined on these values  A data type is called an ADT if a programmer can use it without having access to and also without knowing the details of how the values and operations are implemented Abstract Data Type
  • 5. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 5  The term ADT describes a comprehensive collection of data values and operations  The term data structure refers to the study of data and how to represent data object within a program, that is, the implementation of structured relationship Abstract Data Type and Data Structures
  • 6. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 6  ADT stack(element)  Declare create() → stack  pop(push(e,S)) = S  getTop(stack) → element  is_empty(stack) → Boolean;  is_empty(create) = true  pop(stack) → stack  for all S Î stack, e Î element, is_empty(push(e, S)) = false  pop(create()) = error  push(element, stack) → stack Stack Abstract Data Type
  • 7. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 7 A Survey of Programming Object-oriented Programming Techniques
  • 8. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 8 Unstructured programming Procedural programming Modular programming Object-oriented programming A Survey of Programming
  • 9. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 9  Unstructured programming: the main program directly operates on global data Unstructured programming Program PROGRAM MAIN PROGRAM DATA
  • 10. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 10  With procedural programming, we are able to combine returning sequences of statements into one single place  A procedure call is used to invoke the procedure Procedural Programming
  • 11. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 11  Execution of procedures: after processing, flow of controls proceed where the call was made Procedural Programming Main program Procedure
  • 12. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 12 Procedural programming: the main program coordinates calls to procedures and hands over appropriate data as parameters Procedural Programming Program PROGRAM MAIN PROGRAM DATA PROCEDURE1 PROCEDUR E2 PROCEDUR E3
  • 13. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 13 Modular programming Program Main program data Module1 data+da ta1 Module2 data+dat2 Procedure1 Procedure2 Procedure3
  • 14. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 14 Object-oriented programming: objects of the program interact by sending messages to each other Object-oriented Programming Program Object1 data Object4 data Object 3 data Object2 data
  • 15. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 15 Object-oriented programming is a method of implementation in which  Objects are the fundamental building blocks  Each object is an instance of some type (specification or class)  Objects can interact with each other  Classes are related to each other by inheritance relationship
  • 16. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 16  An object-oriented language is the one that supports objects, and programs divided into objects,  contains objects belonging to a class,  supports inheritance
  • 17. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 17  Objects  Classes  Data abstraction and encapsulation  Inheritance  Reusability  Polymerisation  Dynamic binding  Message passing Basic Concepts of Object-oriented Programming
  • 18. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 18 Objects  Objects are the basic runtime entities in an object- oriented system  Programming problem is analyzed in terms of objects and the nature of communication between them  Each object contains data and code to manipulate the data
  • 19. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 19  Object-oriented programming encapsulates data (attributes) and functions (behaviour) into package called as classes  A class is a user-defined data type Classes
  • 20. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 20  Encapsulation : Combining a number of variables and functions into a single package  Abstraction : It refers to the act of representing essential features without including the details of implementation  Generally, data members are made private and are accessible to only class member functions  This insulation of data from direct access by the program is called data hiding or information hiding
  • 21. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 21  Inheritance is a process by which the objects of one class inherit the properties of another class  Classes in C++ support the concept of hierarchical classification
  • 22. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 22  The concept of inheritance providing feature of reusability by additional features to the existing class without modifying the existing one leads to a new class
  • 23. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 23  Polymorphism means the ability to take more than one form  Polymorphism is a mean by which we can request an object to do something without knowing exactly what kind of object it is, and the object will figure out how to process the request appropriately
  • 24. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 24  Binding refers to the linking of a procedure call to the code to be executed in response to the call  Dynamic binding means that the code associated with a given procedure call is not known until the time of call at runtime  This is associated with polymorphism and inheritance
  • 25. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 25  An OOP consists of a set of objects that communicate with each other  Message for an object is a request for execution of a procedure and therefore will invoke a function in the receiving object that generates the desired result  Message passing involves specifying the name of the object, the name of the function (message), and the information to be sent
  • 26. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 26  A class template is a generic class declaration that allows the user to provide the data structure through parameters that the compiler resolved
  • 27. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 27
  • 28. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 28 Abstract representation of linked list Linked list with header pointer
  • 29. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 29  The C++ STL is a collection of  Containers  Iterators  Algorithms
  • 30. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 30  The STL is a part of the standard C++ class library and can be used as a standard approach for storing and processing data  The task of writing complex application codes can be made easy with the use of STL  The STL allows programmer to use these classes and functions directly in programs to increase productivity
  • 31. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 31 Container class contains other objects. Container is a way to store data, whether the data consists of built-in types such as int and float, or of class objects Container class Description  Vector Array  List Doubly linked list  Slist Singly linked list  Queue Queue structure, that is, FIFO structure  Stack Stack structure, that is, LIFO structure  Deque Combination of stack and queue, having  facility for insertion and removal from both ends  Set Set of unique elements  Map Store key and data pair
  • 32. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 32 Containers are categorized into two types:  Sequence containers  Associative containers
  • 33. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 33 The sequence containers are as follows:  Vectors Lists Deques  The containers that are derived from sequence containers are as follows:  Stacks  Queues  Priority queues  Sequence containers
  • 34. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 34
  • 35. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 35
  • 36. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 36 List of containers and their characteristics
  • 37. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 37 Associative Containers  An associative container is a collection of stored objects that allow fast retrieval using a key  In each container, the key must be unique  There are four standard associative containers classified into two classes:  Sets  (a) Set  (b) Multiset  Maps  (a) Map  (b) Multimap list
  • 38. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 38  The header <algorithm> defines a collection of functions especially designed to be used on ranges of elements  These algorithms can be divided into six groups:  Minimum and maximum algorithm  Numeric algorithms  Non-mutating sequence algorithms  Sorting algorithm  Set operations on sorted sequence  Heap operations
  • 39. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 39  Suppose we create an array of type int storing marks of the student  Then, int marks [6] = {73, 44, 42, 51, 59, 50}
  • 40. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 40  We can use STL sort() assort(marks, marks + 6)  Here, marks is the start and marks + 6 is the end addresses, respectively  Other example of sorting vector is as follows: vector<int> m; /having values 73, 44, 42, 51, 59, 50 sort(m.begin(), m.end() ); // Output is 42, 44, 50, 51, 59, 73 sort(v.begin(), v.end(), greater<int>()); // Output is 73, 59, 51, 50, 44, 42
  • 41. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 41  replace() Replace value in range  fill() Fill range with value  remove() Remove value from range  reverse() Reverse range  sort() Sort elements in range  partial_sort() Partially sort elements in range  nth_element() Sort element in range  binary_search() Test if value exists in sorted arra  merge() Merge sorted ranges  min() Return the lesser of two arguments  max() Return the greater of two arguments  Min_element() Return the smallest element in range  max_element() Return the largest element in range
  • 42. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 42 Iterator—Iterator is pointer like entity, which is used to access individual data items in a container, and it is used to store and retrieve objects in C++ STL defines five different iterators  Forward  Bidirectional  Random access  Input iterator  Output iterator
  • 43. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 43
  • 44. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 44
  • 45. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 45
  • 46. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 46
  • 47. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 47
  • 48. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 48
  • 49. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 49
  • 50. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 50