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 */ }
// …
}
}
Related Topics
Privacy Policy, Terms and Conditions, DMCA Policy and Compliant
Copyright © 2018-2023 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.