Untitled
unknown
plain_text
a year ago
749 B
7
Indexable
#include <vector> #include <iostream> // Funkcija "izdvoji" std::vector<int> izdvoji(std::vector<int>& brojevi, std::function<bool(int)> func) { std::vector<int> rez; for (int broj : brojevi) { if (func(broj)) { rez.push_back(broj); } } return rez; } int main() { std::vector<int> brojevi = {1, 4, 5, 7, 3, 6, 12, 65, 32, 8, 87, 55, 23, 22, 1, 1, 433, 66, 7, 433, 3, 32, 76, 8, 72, 256, 42}; // Lambda izraz za provjeru djeljivosti s 3 auto lambda = { return broj % 3 == 0; }; std::vector<int> rez = izdvoji(brojevi, lambda); for (int i = 0; i < rez.size(); i++) std::cout << rez[i] << " "; // Ispis: 3 6 12 87 66 3 72 42 return 0; }
Editor is loading...
Leave a Comment