SlideShare ist ein Scribd-Unternehmen logo
1 von 50
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

Weitere ähnliche Inhalte

Was ist angesagt?

Lecture 07 Data Structures - Basic Sorting
Lecture 07 Data Structures - Basic SortingLecture 07 Data Structures - Basic Sorting
Lecture 07 Data Structures - Basic Sorting
Haitham El-Ghareeb
 
Lecture 9 - DSA - Python Data Structures
Lecture 9 - DSA - Python Data StructuresLecture 9 - DSA - Python Data Structures
Lecture 9 - DSA - Python Data Structures
Haitham El-Ghareeb
 
Development of a new indexing technique for XML document retrieval
Development of a new indexing technique for XML document retrievalDevelopment of a new indexing technique for XML document retrieval
Development of a new indexing technique for XML document retrieval
Amjad Ali
 

Was ist angesagt? (20)

13. Indexing MTrees - Data Structures using C++ by Varsha Patil
13. Indexing MTrees - Data Structures using C++ by Varsha Patil13. Indexing MTrees - Data Structures using C++ by Varsha Patil
13. Indexing MTrees - Data Structures using C++ by Varsha Patil
 
16. Algo analysis & Design - Data Structures using C++ by Varsha Patil
16. Algo analysis & Design - Data Structures using C++ by Varsha Patil16. Algo analysis & Design - 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
7. Tree - Data Structures using C++ by Varsha Patil7. Tree - 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
4. Recursion - Data Structures using C++ by Varsha Patil4. Recursion - 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
11. Hashing - Data Structures using C++ by Varsha Patil11. Hashing - 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
8. Graph - Data Structures using C++ by Varsha Patil8. Graph - Data Structures using C++ by Varsha Patil
8. Graph - Data Structures using C++ by Varsha Patil
 
Lecture 07 Data Structures - Basic Sorting
Lecture 07 Data Structures - Basic SortingLecture 07 Data Structures - Basic Sorting
Lecture 07 Data Structures - Basic Sorting
 
indexing and hashing
indexing and hashingindexing and hashing
indexing and hashing
 
Lect07
Lect07Lect07
Lect07
 
Ii pu cs practical viva voce questions
Ii pu cs  practical viva voce questionsIi pu cs  practical viva voce questions
Ii pu cs practical viva voce questions
 
Z04506138145
Z04506138145Z04506138145
Z04506138145
 
DSA - Lecture 04
DSA - Lecture 04DSA - Lecture 04
DSA - Lecture 04
 
Chapter 8: tree data structure
Chapter 8:  tree data structureChapter 8:  tree data structure
Chapter 8: tree data structure
 
Lecture 9 - DSA - Python Data Structures
Lecture 9 - DSA - Python Data StructuresLecture 9 - DSA - Python Data Structures
Lecture 9 - DSA - Python Data Structures
 
Data Structures
Data StructuresData Structures
Data Structures
 
ChemExtractor: Enhanced Rule-Based Capture and Identification of PDF Based Pr...
ChemExtractor: Enhanced Rule-Based Capture and Identification of PDF Based Pr...ChemExtractor: Enhanced Rule-Based Capture and Identification of PDF Based Pr...
ChemExtractor: Enhanced Rule-Based Capture and Identification of PDF Based Pr...
 
Development of a new indexing technique for XML document retrieval
Development of a new indexing technique for XML document retrievalDevelopment of a new indexing technique for XML document retrieval
Development of a new indexing technique for XML document retrieval
 
Mapping Domain Names to Categories
Mapping Domain Names to CategoriesMapping Domain Names to Categories
Mapping Domain Names to Categories
 
linked_lists
linked_listslinked_lists
linked_lists
 
Presentation on data preparation with pandas
Presentation on data preparation with pandasPresentation on data preparation with pandas
Presentation on data preparation with pandas
 

Andere mochten auch

Lists, queues and stacks
Lists, queues and stacksLists, queues and stacks
Lists, queues and stacks
andreeamolnar
 
Advanced data structures using c++ 3
Advanced data structures using c++ 3Advanced data structures using c++ 3
Advanced data structures using c++ 3
Shaili Choudhary
 
Data Structure
Data StructureData Structure
Data Structure
sheraz1
 

Andere mochten auch (18)

Discrete Mathematics S. Lipschutz, M. Lipson And V. H. Patil
Discrete Mathematics S. Lipschutz, M. Lipson And V. H. PatilDiscrete Mathematics S. Lipschutz, M. Lipson And V. H. Patil
Discrete Mathematics S. Lipschutz, M. Lipson And V. H. Patil
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
Array,lists and hashes in perl
Array,lists and hashes in perlArray,lists and hashes in perl
Array,lists and hashes in perl
 
Lists, queues and stacks
Lists, queues and stacksLists, queues and stacks
Lists, queues and stacks
 
Classes and objects1
Classes and objects1Classes and objects1
Classes and objects1
 
Constructors and destructors
Constructors and destructorsConstructors and destructors
Constructors and destructors
 
Structured query language functions
Structured query language functionsStructured query language functions
Structured query language functions
 
Advanced data structures using c++ 3
Advanced data structures using c++ 3Advanced data structures using c++ 3
Advanced data structures using c++ 3
 
Structured query language constraints
Structured query language constraintsStructured query language constraints
Structured query language constraints
 
Pp
PpPp
Pp
 
Working with Cookies in NodeJS
Working with Cookies in NodeJSWorking with Cookies in NodeJS
Working with Cookies in NodeJS
 
Stacks in c++
Stacks in c++Stacks in c++
Stacks in c++
 
Data types in c++
Data types in c++Data types in c++
Data types in c++
 
C++ data types
C++ data typesC++ data types
C++ data types
 
Data Structure
Data StructureData Structure
Data Structure
 
Data file handling in c++
Data file handling in c++Data file handling in c++
Data file handling in c++
 
Stacks in algorithems & data structure
Stacks in algorithems & data structureStacks in algorithems & data structure
Stacks in algorithems & data structure
 
stacks in algorithems and data structure
stacks in algorithems and data structurestacks in algorithems and data structure
stacks in algorithems and data structure
 

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

Data-centric AI and the convergence of data and model engineering: opportunit...
Data-centric AI and the convergence of data and model engineering:opportunit...Data-centric AI and the convergence of data and model engineering:opportunit...
Data-centric AI and the convergence of data and model engineering: opportunit...
Paolo Missier
 

Ähnlich wie 15. STL - Data Structures using C++ by Varsha Patil (20)

Data-centric AI and the convergence of data and model engineering: opportunit...
Data-centric AI and the convergence of data and model engineering:opportunit...Data-centric AI and the convergence of data and model engineering:opportunit...
Data-centric AI and the convergence of data and model engineering: opportunit...
 
Object-Oriented Database Model For Effective Mining Of Advanced Engineering M...
Object-Oriented Database Model For Effective Mining Of Advanced Engineering M...Object-Oriented Database Model For Effective Mining Of Advanced Engineering M...
Object-Oriented Database Model For Effective Mining Of Advanced Engineering M...
 
An Overview of Entity Framework
An Overview of Entity FrameworkAn Overview of Entity Framework
An Overview of Entity Framework
 
Unit4
Unit4Unit4
Unit4
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented Programming
 
Birasa 1
Birasa 1Birasa 1
Birasa 1
 
JAVA PROGRAMMING
JAVA PROGRAMMING JAVA PROGRAMMING
JAVA PROGRAMMING
 
Topic 1 PBO
Topic 1 PBOTopic 1 PBO
Topic 1 PBO
 
Advance oops concepts
Advance oops conceptsAdvance oops concepts
Advance oops concepts
 
Semantic Annotation of Documents
Semantic Annotation of DocumentsSemantic Annotation of Documents
Semantic Annotation of Documents
 
NISO Virtual Conference Scientific Data Management: Caring for Your Instituti...
NISO Virtual Conference Scientific Data Management: Caring for Your Instituti...NISO Virtual Conference Scientific Data Management: Caring for Your Instituti...
NISO Virtual Conference Scientific Data Management: Caring for Your Instituti...
 
JAVA PROGRAMMINGD
JAVA PROGRAMMINGDJAVA PROGRAMMINGD
JAVA PROGRAMMINGD
 
Hughes RDAP11 Data Publication Repositories
Hughes RDAP11 Data Publication RepositoriesHughes RDAP11 Data Publication Repositories
Hughes RDAP11 Data Publication Repositories
 
Object Oriented Programming Lecture Notes
Object Oriented Programming Lecture NotesObject Oriented Programming Lecture Notes
Object Oriented Programming Lecture Notes
 
Organizing the Data Chaos of Scientists
Organizing the Data Chaos of ScientistsOrganizing the Data Chaos of Scientists
Organizing the Data Chaos of Scientists
 
OOP_1_TEG
OOP_1_TEGOOP_1_TEG
OOP_1_TEG
 
Programming with Objective-C
Programming with Objective-CProgramming with Objective-C
Programming with Objective-C
 
Overview of entity framework by software outsourcing company india
Overview of entity framework by software outsourcing company indiaOverview of entity framework by software outsourcing company india
Overview of entity framework by software outsourcing company india
 
Dbms
DbmsDbms
Dbms
 
C++
C++C++
C++
 

Kürzlich hochgeladen

Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get CytotecAbortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Riyadh +966572737505 get cytotec
 
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
amitlee9823
 
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night StandCall Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
amitlee9823
 
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
amitlee9823
 
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
amitlee9823
 
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
amitlee9823
 
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
amitlee9823
 
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men 🔝Bangalore🔝 Esc...
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men  🔝Bangalore🔝   Esc...➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men  🔝Bangalore🔝   Esc...
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men 🔝Bangalore🔝 Esc...
amitlee9823
 

Kürzlich hochgeladen (20)

Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get CytotecAbortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
 
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
 
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night StandCall Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
 
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort ServiceBDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
 
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
 
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
 
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
 
April 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's AnalysisApril 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's Analysis
 
Halmar dropshipping via API with DroFx
Halmar  dropshipping  via API with DroFxHalmar  dropshipping  via API with DroFx
Halmar dropshipping via API with DroFx
 
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
 
Sampling (random) method and Non random.ppt
Sampling (random) method and Non random.pptSampling (random) method and Non random.ppt
Sampling (random) method and Non random.ppt
 
Predicting Loan Approval: A Data Science Project
Predicting Loan Approval: A Data Science ProjectPredicting Loan Approval: A Data Science Project
Predicting Loan Approval: A Data Science Project
 
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
 
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
 
Capstone Project on IBM Data Analytics Program
Capstone Project on IBM Data Analytics ProgramCapstone Project on IBM Data Analytics Program
Capstone Project on IBM Data Analytics Program
 
Accredited-Transport-Cooperatives-Jan-2021-Web.pdf
Accredited-Transport-Cooperatives-Jan-2021-Web.pdfAccredited-Transport-Cooperatives-Jan-2021-Web.pdf
Accredited-Transport-Cooperatives-Jan-2021-Web.pdf
 
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men 🔝Bangalore🔝 Esc...
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men  🔝Bangalore🔝   Esc...➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men  🔝Bangalore🔝   Esc...
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men 🔝Bangalore🔝 Esc...
 
Anomaly detection and data imputation within time series
Anomaly detection and data imputation within time seriesAnomaly detection and data imputation within time series
Anomaly detection and data imputation within time series
 
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
 
Midocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxMidocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFx
 

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