Home | | Object Oriented Programming | Containers - C++

Chapter: Object Oriented Programming(OOP) : Basic Characteristics of OOP

Containers - C++

(hold sequences in difference ways)

CONTAINERS

(hold sequences in difference ways)

 

The simplest algorithm: find()


find()

void f(vector<int>& v, int x)   // works for vector of ints

{

 

vector<int>::iterator p = find(v.begin(),v.end(),x); if (p!=v.end()) { /* we found x */ }

 

// …

}

void f(list<string>& v, string x)        // works for list of strings

{

 

list<string>::iterator p = find(v.begin(),v.end(),x); if (p!=v.end()) { /* we found x */ }

// …

}

 

void f(set<double>& v, double x)     // works for set of doubles

{

 

set<double>::iterator p = find(v.begin(),v.end(),x); if (p!=v.end()) { /* we found x */ }

// …

}

}

 

 

Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail
Object Oriented Programming(OOP) : Basic Characteristics of OOP : Containers - C++ |


Privacy Policy, Terms and Conditions, DMCA Policy and Compliant

Copyright © 2018-2023 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.