logo

وظيفة خوارزمية C++ متساوية ()

تقوم خوارزمية C++‎ بمقارنة العناصر الموجودة في كلتا الحاويتين وإرجاع قيمة حقيقية إذا تم العثور على جميع العناصر الموجودة في كلتا الحاويتين متطابقتين. النطاق الأول من [first1,last1) والثاني يبدأ من first2.

بناء الجملة

 template bool equal(InputIterator1 first1, InputIterator1 last1,InputIterator2 first2); template bool equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first1, BinaryPredicate pred); 

معامل

أولا1 : إنه مكرر إدخال للعنصر الأول من [first1, last1).

last1 : إنه مكرر إدخال للعنصر الأخير في [first1, last1).

first2 : إنه مكرر إدخال للعنصر الأول من [first2، last2).

قبل : هي دالة ثنائية تقبل عنصرين كوسيطتين وتنفذ المهمة التي صممتها الدالة.

قيمة الإرجاع

ترجع الدالة القيمة true إذا كانت جميع العناصر الموجودة في كلتا الحاويتين متطابقة، وإلا فإنها ترجع false.

مثال 1

 #include #include #include using namespace std; bool newpredicate(int m, int n) { return(m==n); } int main() { int newints[]={20,40,60,80,100}; std::vector newvector(newints, newints+5); if(std::equal(newvector.begin(),newvector.end(),newints)) std::cout&lt;<'both the containers have matching elements.
'; else std::cout<<'both difference newvector[3]="81;" if(std::equal(newvector.begin(),newvector.end(),newints,newpredicate)) equal containers.
'; do not elements. 
'; return 0; } < pre> <p> <strong>Output:</strong> </p> <pre> Both the containers have matching elements. Both the containers do not have equal elements. </pre> <h2>Example 2</h2> <pre> #include using namespace std; int main() { int u1[]={10,20,30,40,50}; std::vector vec_1(u1,u1+sizeof(u1)/sizeof(int)); std::cout&lt;<'the vector consists of:'; for(unsigned int k="0;" k<vec_1.size(); k++) std::cout<<' '<<vec_1[k]; std::cout<<'
'; if(std::equal(vec_1.begin(),vec_1.end(),u1)) std::cout<<'both the containers have equal elements.
'; else cout<<'both different elements.'; } < pre> <p> <strong>Output:</strong> </p> <pre> The vector consists of: 10, 20,30,40,50 Both the containers have equal elements. </pre> <h2>Complexity</h2> <p>The function has linear complexity from the first1 element to the last1 element.</p> <h2>Data races</h2> <p>Objects in both ranges are accessed.</p> <h2>Exceptions</h2> <p>The function throws an exception if any of the argument throws one. </p> <br></'the></pre></'both>

مثال 2

 #include using namespace std; int main() { int u1[]={10,20,30,40,50}; std::vector vec_1(u1,u1+sizeof(u1)/sizeof(int)); std::cout&lt;<\'the vector consists of:\'; for(unsigned int k="0;" k<vec_1.size(); k++) std::cout<<\' \'<<vec_1[k]; std::cout<<\'
\'; if(std::equal(vec_1.begin(),vec_1.end(),u1)) std::cout<<\'both the containers have equal elements.
\'; else cout<<\'both different elements.\'; } < pre> <p> <strong>Output:</strong> </p> <pre> The vector consists of: 10, 20,30,40,50 Both the containers have equal elements. </pre> <h2>Complexity</h2> <p>The function has linear complexity from the first1 element to the last1 element.</p> <h2>Data races</h2> <p>Objects in both ranges are accessed.</p> <h2>Exceptions</h2> <p>The function throws an exception if any of the argument throws one. </p> <br></\'the>

تعقيد

تحتوي الدالة على تعقيد خطي من العنصر الأول إلى العنصر الأخير.

سباقات البيانات

يتم الوصول إلى الكائنات في كلا النطاقين.

الاستثناءات

تطرح الدالة استثناءً إذا قامت أي من الوسيطات بطرح استثناء.