STL - Algorithm/Algorithm - Non-Modifying
Algorithm - equal()
Programmer.
2016. 2. 7. 19:37
소스)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | #include<vector> #include<iostream> #include<algorithm> bool compare(int i, int j) { if (i == j) return true; return false; } void main() { int Array[] = { 10,20,30,40,50 }; std::vector<int> Vector = { 10,20,30,40,50}; if (std::equal(Vector.begin(), Vector.end(), Array)) std::cout << "Same" << std::endl; else std::cout << "not Same" << std::endl; Array[1] = 123; if (std::equal(Vector.begin(), Vector.end(), Array,compare)) std::cout << "Same" << std::endl; else std::cout << "not Same" << std::endl; } | cs |
내용)
equal함수는 파라메터에 따라서 다른 기능을 합니다.
- equal(x,y,z)
equal(x,y,z)함수는 iterator x 부터 iterator y 사이에 있는 데이터들과 z를 비교하여 같으면 true를 다르면 false를 리턴합니다. - equal(w,x,y,z)
equalw,x,y,z,)함수는 iterator w부터 iterator x 사이에 있는 데이터 들과 y를 z를 이용하여 비교하며 조건에 맞다면 true를 아니면 false를 리턴합니다.
결과)