SlideShare a Scribd company logo
1 of 39
STL Algorithms
Presented by: ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
What is STL? ,[object Object],[object Object],[object Object],[object Object]
Uses of STL – Why should it be used? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The three parts of STL   ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Introduction to STL Algorithms ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The sort() function ,[object Object],[object Object],An example : #include <iostream> #include <algorithm> void  main() { int  arr[10]={2,4,1,5,6,7,-11,23,9,-1999}; for (int a=0;a<10;a++) { cout <<arr[a]<<&quot;&quot;; } cout <<endl; sort (arr,arr+10); for (a=0;a<10;a++) { cout<<arr[a]<<&quot;&quot;;; } }
Extended Example #include<algorithm> #include<iostream.h> #include<list.h> using namespace std; void main() { list <int>  dc,dc2; dc.push_back(9); dc.push_back(10); dc.push_back(-11); dc2=dc; while(! dc.empty() ) { cout<<dc.front(); dc.pop_front(); cout<<endl; } dc2.sort(); cout<<endl; while(! dc2.empty() ) { cout<<dc2.front(); dc2.pop_front(); cout<<endl; } }
The rotate() function ,[object Object],[object Object],An example : #include <iostream> #include <algorithm> int  arr[10]={1,2,3,4,5,6,7,8,9,10}; rotate (arr,arr+4,arr+10); for ( int  a=0;a<10;a++) { cout <<arr[a]<<&quot;&quot;; } cout <<endl; [ Output will be “ 5 6 7 8 9 10 1 2 3 4 5”]
The rotate_copy() function ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The reverse() function ,[object Object],[object Object],An example : #include <iostream> #include <algorithm> char  arr[5]={'a','b','c','d','e'}; reverse (arr,arr+5); for (int a=0;a<5;a++) { cout <<arr[a]<<&quot;&quot;; } cout <<endl; [Output will be “e d c b a”]
Extended Example #include<algorithm> #include<iostream.h> #include<list.h> #include<vector.h> using namespace std; void main() { vector <int> v; vector <int> ::iterator it; v.push_back(10); v.push_back(11); v.push_back(12); v.push_back(13); v.push_back(14); v.push_back(15); for(it=v.begin();it!=v.end();it++) { cout<<*it<<&quot; &quot;; } cout<<endl; reverse(v.begin(),v.end()); cout<<endl; for(it=v.begin();it!=v.end();it++) { cout<<*it<<&quot; &quot;; } }
The random shuffle() function ,[object Object],[object Object],An example : #include <iostream> #include <algorithm> char  arr[5]={'a','b','c','d','e'}; random_shuffle (arr,arr+5); for (int a=0;a<5;a++) { cout <<arr[a]<<&quot;&quot;; } cout <<endl; [Output can be “e b d c a”]
Extended Example #include<algorithm> #include<iostream.h> #include<vector.h> using namespace std; void main() { vector <int> v; vector <int> ::iterator it; v.push_back(1); v.push_back(2); v.push_back(3); v.push_back(4); v.push_back(5); v.push_back(6); v.push_back(7); v.push_back(8); v.push_back(9); v.push_back(10); for(it=v.begin();it!=v.end();it++) { cout<<*it<<&quot; &quot;; } cout<<endl; random_shuffle(v.begin(),v.end()); cout<<endl; for(it=v.begin();it!=v.end();it++) { cout<<*it<<&quot; &quot;; }
The find function ,[object Object],[object Object],[object Object],An example : #include <iostream> #include <algorithm> void  main() {   c har  arr[20]=&quot;abcdefgh&quot;; char  *p; p= find (arr,arr+7,'d'); puts (p); }
The replace function ,[object Object],[object Object],An example : #include <iostream> #include <algorithm> void  main() { char  arr[20]=&quot;faizansuhail&quot;; replace (arr,&arr[10],'a','b'); puts (arr); }
The fill function ,[object Object],[object Object],An example : #include <iostream> #include <algorithm> void  main() { int  ar[20]={23,45,56,4,45,23}; fill (ar,ar+5,45); for (int a=0;a<5;a++) cout <<&quot;&quot;<<ar[a]; }
The remove function ,[object Object],[object Object],An example : #include <iostream> #include <algorithm> void  main() { char  arr[20]=&quot;abcdefgh&quot;; char  *p; p= remove (arr,&arr[7],'h'); puts (p); }
The search function ,[object Object],[object Object],An example : #include <iostream> #include <algorithm> void   main() { char  source[20]=&quot;abcdefgh&quot;; char  tar[20]=&quot;fgh&quot;,*p; p= search (source,&source[7],tar,&tar[2]); if (*p==source[7]) { cout <<&quot;not found&quot;; } else  { puts (p); cout <<&quot;found&quot;; } }
The swap function ,[object Object],[object Object],[object Object]
An example : #include <iostream> #include <algorithm> #include  <vector> void   main() { vector <int> obj; vector <int> tar; obj.push_back(1); obj.push_back(2); obj.push_back(3); tar.push_back(4); tar.push_back(5); tar.push_back(6); swap(obj,tar); cout<<obj[0]; cout<<obj[1]; cout<<obj[2]; cout<<tar[0]; cout<<tar[1]; cout<<tar[2];} }
The swap ranges function ,[object Object],[object Object],An example : #include <iostream> #include <algorithm> #include  <vector> void   main() { void  main() { int  arr[]={1,2,3,4,5,6}; int  tar[]={6,7,8,9,10,11,12}; swap_ranges(arr,arr+6,tar); for (int a=0;a<5;a++) { cout<<&quot;&quot;<<arr[a]; } } }
The count function ,[object Object],[object Object]
An example : #include <iostream> #include <algorithm> #include  <vector> void   main() { int  a; int  arr[]={1,2,3,4,5,6,7}; a=mycount(&arr[0],&arr[7],7); cout<<&quot;7 come&quot;; cout<<&quot;&quot;; cout<<a; cout<<&quot;times&quot;; cout<<&quot;************************&quot;; } int  mycount(int *p,int *q,int b) { int  a=0; while (p!=q) { if (*p++==7) { a++; } } return  a; }
The minimum function ,[object Object],[object Object],An example : #include <iostream> #include <algorithm> #include  <vector> void   main() { int  *a; char  *p; int  arr[]={1,2,3,4,5,6,7}; char  tar[]={'a','b','c','d'}; a= min_element (arr,arr+7); p= min_element (tar,tar+4); cout<<&quot;&quot;; cout<<*a; cout<<&quot;&quot;; cout<<*p; cout<<&quot;&quot;; }
The maximum function ,[object Object],[object Object],An example : #include <iostream> #include <algorithm> #include  <vector> void   main() { int  *a; char   *p; int   arr[]={1,2,3,4,5,6,7}; char  tar[]={'a','b','c','d'}; a= max_element (arr,arr+7); p= max_element (tar,tar+4); cout<<&quot;&quot;; cout<<*a; cout<<&quot;&quot;; cout<<*p; cout<<&quot;&quot;;}
The equal function ,[object Object],[object Object]
An example : #include <iostream> #include <algorithm> #include  <vector> void   main() { int  arr[]={1,2,3,4,5}; int  brr[]={1,2,3,4,5}; int  crr[]={1,2,3,4,1}; if (equal(arr,arr+5,brr)) { cout<<&quot;ok&quot;; } else { cout<<&quot;not ok&quot;; } if (equal(arr,arr+5,crr)) { cout<<&quot;ok&quot;; } else { cout<<&quot;not ok&quot;; }
The for_each() function ,[object Object],[object Object],An example : #include <iostream> #include <algorithm> void   main() { myfunction (int i) { i=i+2 } void  main() { int  arr[]={1,2,3,4,5}; for_each(arr,arr+5,myfunction); cout<<&quot;&quot;<<arr; }
The find_if() function ,[object Object],[object Object],An example : #include <iostream> #include <algorithm> void   main() { bool  iseven(int i) { if(i%2==0) return  true; else  return  false } void  main() { int  arr[]={1,2,3,4,5}; it =find_if(arr,arr+5,iseven); cout<<&quot;&quot;<<*it;}
The binary search() function ,[object Object],[object Object],An example : #include <iostream> #include <algorithm> void   main() { int arr[ ]={1,2,3,4,5}; int *it; bool a; a=binary_search(arr,arr+5,4); cout<<a; }
The merge function ,[object Object],[object Object],An example : #include <iostream> #include <algorithm> void main() { int arr[]={1,2,3,4,5}; int brr[]={6,7,8,9,10}; int crr[10]; merge(arr,arr+5,brr,brr+5,crr); for(int a=0;a<10;a++) { cout<<crr[a]; } }
The copy function ,[object Object],[object Object],An example : #include <iostream> #include <algorithm> void main() { int arr[   ]={1,2,3,4,5};   int crr[10]; copy  (arr,arr+5,crr); for(int a=0;a< 5 ;a++) { cout<<crr[a] <<“” ; } }
The lexographical function ,[object Object],[object Object],An example : #include <iostream> #include <algorithm> void  main() { string a=“pakistan”; string b=“waziristan”; if(lexographical_compare(a, a+7, b, b+9)) cout<<“sab sey pehle Pakistan”<<endl }
The make_heap function ,[object Object],[object Object],[object Object],[object Object],An example : #include <iostream> #include <algorithm> void  main() {   int arr[10]={1,2,3,4,5,6,7,8,9}; for(int a=0;a<10;a++) { cout<<arr[a]<<&quot;&quot;; } cout<<endl; make_heap(arr, &arr[9]); for(a=0;a<10;a++) { cout<<arr[a]<<&quot;&quot;;; } }
The push_heap function ,[object Object],[object Object],[object Object],[object Object],An example : #include <iostream> #include <algorithm> void  main() {   int arr[10]={1,2,3,4,5,6,7,8,9}; make_heap(arr, &arr[9]); arr[9]=31; push_heap(arr, &arr[10]); for(a=0;a<10;a++) { cout<<arr[a]<<&quot;&quot;;; }
The pop_heap function ,[object Object],[object Object],[object Object],[object Object],An example : #include <iostream> #include <algorithm> void  main() { int arr[10]={1,2,3,4,5,6,7,8,9}; make_heap (arr, &arr[9]); pop_heap(arr, &arr[8]); for(int a=0;a<10;a++) { cout<<arr[a]<<&quot;&quot;;; }
The sort_heap function ,[object Object],[object Object],An example : #include <iostream> #include <algorithm> void  main() { int arr[10]={1,2,3,4,5,6,7,8,9}; make_heap(arr, arr[8]); arr[9]=31; push_heap(arr,&arr[9]); for(a=0;a<10;a++) { cout<<arr[a]<<&quot;&quot;;; }
Q&A Session

More Related Content

What's hot

Constructor and Destructor
Constructor and DestructorConstructor and Destructor
Constructor and Destructor
Kamal Acharya
 
Refactoring Functional Type Classes
Refactoring Functional Type ClassesRefactoring Functional Type Classes
Refactoring Functional Type Classes
John De Goes
 

What's hot (20)

Trees and Hierarchies in SQL
Trees and Hierarchies in SQLTrees and Hierarchies in SQL
Trees and Hierarchies in SQL
 
Queues
QueuesQueues
Queues
 
Constructor and destructor in C++
Constructor and destructor in C++Constructor and destructor in C++
Constructor and destructor in C++
 
Linked List - Insertion & Deletion
Linked List - Insertion & DeletionLinked List - Insertion & Deletion
Linked List - Insertion & Deletion
 
Linked list
Linked listLinked list
Linked list
 
Strings in c language
Strings in  c languageStrings in  c language
Strings in c language
 
Why functional programming and category theory strongly matters
Why functional programming and category theory strongly mattersWhy functional programming and category theory strongly matters
Why functional programming and category theory strongly matters
 
Indy Code - Taking a Gamble With F#: Implementing Blackjack
Indy Code - Taking a Gamble With F#: Implementing BlackjackIndy Code - Taking a Gamble With F#: Implementing Blackjack
Indy Code - Taking a Gamble With F#: Implementing Blackjack
 
Linklist
LinklistLinklist
Linklist
 
Stl Containers
Stl ContainersStl Containers
Stl Containers
 
Recursive Query Throwdown
Recursive Query ThrowdownRecursive Query Throwdown
Recursive Query Throwdown
 
C programming - String
C programming - StringC programming - String
C programming - String
 
C Programming Lab manual 18CPL17
C Programming Lab manual 18CPL17C Programming Lab manual 18CPL17
C Programming Lab manual 18CPL17
 
Constructor and Types of Constructors
Constructor and Types of ConstructorsConstructor and Types of Constructors
Constructor and Types of Constructors
 
C++ Standard Template Library
C++ Standard Template LibraryC++ Standard Template Library
C++ Standard Template Library
 
Constructor and Destructor
Constructor and DestructorConstructor and Destructor
Constructor and Destructor
 
Presentation on function
Presentation on functionPresentation on function
Presentation on function
 
Refactoring Functional Type Classes
Refactoring Functional Type ClassesRefactoring Functional Type Classes
Refactoring Functional Type Classes
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
Map(), flatmap() and reduce() are your new best friends: simpler collections,...
Map(), flatmap() and reduce() are your new best friends: simpler collections,...Map(), flatmap() and reduce() are your new best friends: simpler collections,...
Map(), flatmap() and reduce() are your new best friends: simpler collections,...
 

Viewers also liked

Operator overloading
Operator overloadingOperator overloading
Operator overloading
farhan amjad
 
C++ Advanced
C++ AdvancedC++ Advanced
C++ Advanced
Vivek Das
 
Exception handling and templates
Exception handling and templatesException handling and templates
Exception handling and templates
farhan amjad
 
Building Embedded Linux
Building Embedded LinuxBuilding Embedded Linux
Building Embedded Linux
Sherif Mousa
 

Viewers also liked (20)

The Style of C++ 11
The Style of C++ 11The Style of C++ 11
The Style of C++ 11
 
Idiomatic C++
Idiomatic C++Idiomatic C++
Idiomatic C++
 
Distributed Systems Design
Distributed Systems DesignDistributed Systems Design
Distributed Systems Design
 
Improving The Quality of Existing Software
Improving The Quality of Existing SoftwareImproving The Quality of Existing Software
Improving The Quality of Existing Software
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
C++ Advanced
C++ AdvancedC++ Advanced
C++ Advanced
 
Web Service Basics and NWS Setup
Web Service  Basics and NWS SetupWeb Service  Basics and NWS Setup
Web Service Basics and NWS Setup
 
Bjarne Stroustrup - The Essence of C++: With Examples in C++84, C++98, C++11,...
Bjarne Stroustrup - The Essence of C++: With Examples in C++84, C++98, C++11,...Bjarne Stroustrup - The Essence of C++: With Examples in C++84, C++98, C++11,...
Bjarne Stroustrup - The Essence of C++: With Examples in C++84, C++98, C++11,...
 
Operator overloading
Operator overloading Operator overloading
Operator overloading
 
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
 
Solid principles of oo design
Solid principles of oo designSolid principles of oo design
Solid principles of oo design
 
SOLID Principles part 2
SOLID Principles part 2SOLID Principles part 2
SOLID Principles part 2
 
Programming In C++
Programming In C++ Programming In C++
Programming In C++
 
SOLID Principles part 1
SOLID Principles part 1SOLID Principles part 1
SOLID Principles part 1
 
Exception handling and templates
Exception handling and templatesException handling and templates
Exception handling and templates
 
Inheritance, polymorphisam, abstract classes and composition)
Inheritance, polymorphisam, abstract classes and composition)Inheritance, polymorphisam, abstract classes and composition)
Inheritance, polymorphisam, abstract classes and composition)
 
Memory Management In C++
Memory Management In C++Memory Management In C++
Memory Management In C++
 
Building Embedded Linux
Building Embedded LinuxBuilding Embedded Linux
Building Embedded Linux
 
Abstract Base Class and Polymorphism in C++
Abstract Base Class and Polymorphism in C++Abstract Base Class and Polymorphism in C++
Abstract Base Class and Polymorphism in C++
 
Keys to Continuous Delivery Success - Mark Warren, Product Director, Perforc...
Keys to Continuous  Delivery Success - Mark Warren, Product Director, Perforc...Keys to Continuous  Delivery Success - Mark Warren, Product Director, Perforc...
Keys to Continuous Delivery Success - Mark Warren, Product Director, Perforc...
 

Similar to STL ALGORITHMS

computer notes - Data Structures - 8
computer notes - Data Structures - 8computer notes - Data Structures - 8
computer notes - Data Structures - 8
ecomputernotes
 
Practical Meta Programming
Practical Meta ProgrammingPractical Meta Programming
Practical Meta Programming
Reggie Meisler
 
Unit 4
Unit 4Unit 4
Unit 4
siddr
 

Similar to STL ALGORITHMS (20)

Synapse india complain sharing info on chapter 8 operator overloading
Synapse india complain sharing info on chapter 8   operator overloadingSynapse india complain sharing info on chapter 8   operator overloading
Synapse india complain sharing info on chapter 8 operator overloading
 
The STL
The STLThe STL
The STL
 
Bw14
Bw14Bw14
Bw14
 
Lecture5
Lecture5Lecture5
Lecture5
 
computer notes - Data Structures - 8
computer notes - Data Structures - 8computer notes - Data Structures - 8
computer notes - Data Structures - 8
 
Java 5 Features
Java 5 FeaturesJava 5 Features
Java 5 Features
 
Arrays
ArraysArrays
Arrays
 
Lecture 3 c++
Lecture 3 c++Lecture 3 c++
Lecture 3 c++
 
C++ STL 概觀
C++ STL 概觀C++ STL 概觀
C++ STL 概觀
 
Practical Meta Programming
Practical Meta ProgrammingPractical Meta Programming
Practical Meta Programming
 
Unit 4
Unit 4Unit 4
Unit 4
 
C++11 - A Change in Style - v2.0
C++11 - A Change in Style - v2.0C++11 - A Change in Style - v2.0
C++11 - A Change in Style - v2.0
 
Dynamic Objects,Pointer to function,Array & Pointer,Character String Processing
Dynamic Objects,Pointer to function,Array & Pointer,Character String ProcessingDynamic Objects,Pointer to function,Array & Pointer,Character String Processing
Dynamic Objects,Pointer to function,Array & Pointer,Character String Processing
 
Data Structure In C#
Data Structure In C#Data Structure In C#
Data Structure In C#
 
Bt0065
Bt0065Bt0065
Bt0065
 
B T0065
B T0065B T0065
B T0065
 
Python 3000
Python 3000Python 3000
Python 3000
 
C++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptxC++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptx
 
C++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptxC++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptx
 
C Programming - Refresher - Part III
C Programming - Refresher - Part IIIC Programming - Refresher - Part III
C Programming - Refresher - Part III
 

Recently uploaded

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
ssuserdda66b
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Recently uploaded (20)

Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 

STL ALGORITHMS

  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8. Extended Example #include<algorithm> #include<iostream.h> #include<list.h> using namespace std; void main() { list <int> dc,dc2; dc.push_back(9); dc.push_back(10); dc.push_back(-11); dc2=dc; while(! dc.empty() ) { cout<<dc.front(); dc.pop_front(); cout<<endl; } dc2.sort(); cout<<endl; while(! dc2.empty() ) { cout<<dc2.front(); dc2.pop_front(); cout<<endl; } }
  • 9.
  • 10.
  • 11.
  • 12. Extended Example #include<algorithm> #include<iostream.h> #include<list.h> #include<vector.h> using namespace std; void main() { vector <int> v; vector <int> ::iterator it; v.push_back(10); v.push_back(11); v.push_back(12); v.push_back(13); v.push_back(14); v.push_back(15); for(it=v.begin();it!=v.end();it++) { cout<<*it<<&quot; &quot;; } cout<<endl; reverse(v.begin(),v.end()); cout<<endl; for(it=v.begin();it!=v.end();it++) { cout<<*it<<&quot; &quot;; } }
  • 13.
  • 14. Extended Example #include<algorithm> #include<iostream.h> #include<vector.h> using namespace std; void main() { vector <int> v; vector <int> ::iterator it; v.push_back(1); v.push_back(2); v.push_back(3); v.push_back(4); v.push_back(5); v.push_back(6); v.push_back(7); v.push_back(8); v.push_back(9); v.push_back(10); for(it=v.begin();it!=v.end();it++) { cout<<*it<<&quot; &quot;; } cout<<endl; random_shuffle(v.begin(),v.end()); cout<<endl; for(it=v.begin();it!=v.end();it++) { cout<<*it<<&quot; &quot;; }
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21. An example : #include <iostream> #include <algorithm> #include <vector> void main() { vector <int> obj; vector <int> tar; obj.push_back(1); obj.push_back(2); obj.push_back(3); tar.push_back(4); tar.push_back(5); tar.push_back(6); swap(obj,tar); cout<<obj[0]; cout<<obj[1]; cout<<obj[2]; cout<<tar[0]; cout<<tar[1]; cout<<tar[2];} }
  • 22.
  • 23.
  • 24. An example : #include <iostream> #include <algorithm> #include <vector> void main() { int a; int arr[]={1,2,3,4,5,6,7}; a=mycount(&arr[0],&arr[7],7); cout<<&quot;7 come&quot;; cout<<&quot;&quot;; cout<<a; cout<<&quot;times&quot;; cout<<&quot;************************&quot;; } int mycount(int *p,int *q,int b) { int a=0; while (p!=q) { if (*p++==7) { a++; } } return a; }
  • 25.
  • 26.
  • 27.
  • 28. An example : #include <iostream> #include <algorithm> #include <vector> void main() { int arr[]={1,2,3,4,5}; int brr[]={1,2,3,4,5}; int crr[]={1,2,3,4,1}; if (equal(arr,arr+5,brr)) { cout<<&quot;ok&quot;; } else { cout<<&quot;not ok&quot;; } if (equal(arr,arr+5,crr)) { cout<<&quot;ok&quot;; } else { cout<<&quot;not ok&quot;; }
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.