87
for (int i = 0; i
for ( int j = n-1; i
if (cmp.lessthan(v[j],v[j-1])) {
T temp = v[j];
v[j] = v[j-1];
v[j-1] = temp;
}
}
for_each() algoritm yordamida har xil ko‘rinishidagi qayta ishlashni va har bir
elementni modifikatsiyasini ko‘rish mumkin.
Template
void for_each(vector- a, function op)
{
for( int i=0; i}
for_each() algoritmining qo‘llanishi:
# include
class StudentPrint
{public:
void operator() (Student elem){ if (elem.rating>5) elem.print();}
};
main()
{
vector coll(5);
coll.input();
StudentPrint cmp;
for_each(coll, cmp);
}