SlideShare una empresa de Scribd logo
1 de 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

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Doubly Linked List
Doubly Linked ListDoubly Linked List
Doubly Linked List
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data Structure
 
Bfs and Dfs
Bfs and DfsBfs and Dfs
Bfs and Dfs
 
Stl Containers
Stl ContainersStl Containers
Stl Containers
 
Trees, Binary Search Tree, AVL Tree in Data Structures
Trees, Binary Search Tree, AVL Tree in Data Structures Trees, Binary Search Tree, AVL Tree in Data Structures
Trees, Binary Search Tree, AVL Tree in Data Structures
 
Set methods in python
Set methods in pythonSet methods in python
Set methods in python
 
Functions in C
Functions in CFunctions in C
Functions in C
 
Standard template library
Standard template libraryStandard template library
Standard template library
 
Strings Functions in C Programming
Strings Functions in C ProgrammingStrings Functions in C Programming
Strings Functions in C Programming
 
Searching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data StructureSearching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data Structure
 
Queue
QueueQueue
Queue
 
Data structure , stack , queue
Data structure , stack , queueData structure , stack , queue
Data structure , stack , queue
 
Introduction to Recursion (Python)
Introduction to Recursion (Python)Introduction to Recursion (Python)
Introduction to Recursion (Python)
 
What is Tuple in python? | Python Tuple Tutorial | Edureka
What is Tuple in python? | Python Tuple Tutorial | EdurekaWhat is Tuple in python? | Python Tuple Tutorial | Edureka
What is Tuple in python? | Python Tuple Tutorial | Edureka
 
Types of Constructor in C++
Types of Constructor in C++Types of Constructor in C++
Types of Constructor in C++
 
File handling in Python
File handling in PythonFile handling in Python
File handling in Python
 
Python-Encapsulation.pptx
Python-Encapsulation.pptxPython-Encapsulation.pptx
Python-Encapsulation.pptx
 
Standard Template Library
Standard Template LibraryStandard Template Library
Standard Template Library
 
Applications of stack
Applications of stackApplications of stack
Applications of stack
 
Priority queues
Priority queuesPriority queues
Priority queues
 

Destacado

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
 

Destacado (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 a 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 a 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
 

Último

Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 

Último (20)

How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
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
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
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
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
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
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
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
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.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.