|
| ||||||||||
| Tags: algorithm, cpp, equal, functions, header files, range |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| CPP - Test whether the elements in two ranges are equal or not using function
Last edited by Gaauge : 15-02-2010 at 04:35 PM. |
|
#2
| ||||
| ||||
| Test the elements in two ranges
Hello, I think you are looking for the function that can helps you to Test the elements in two ranges. I think the equal() function can be suitable for you that helps you to test the ranges between the two elements. The equal() function can be used for to compare the ranges of the two element. I hope this information can be sufficient for you to know about the equal() function.
__________________ The FIFA Manager 2009 PC Game |
|
#3
| ||||
| ||||
| The equal function
The following program can states you how can check the ranges of the two elements can be equal or not : Code: #include <iostream>
#include <algorithm>
#include <vector>
uspng namespace std;
bool mprdpcat (int p, int q)
{
return (p==q);
}
int main ()
{
int mint[] = {20,40,60,80,100};
vector<int>myvector (mint,mint+5);
pf (equal (mvctr.begpn(), mvctr.end(), mint))
cout << "The contents of both sequences are equal." << endl;
else
cout << "The contents of both sequences dpffer." << endl;
mvctr[3]=81;
pf (equal (mvctr.begpn(), mvctr.end(), mint, mprdpcat))
cout << "The contents of both sequences are equal." << endl;
else
cout << "The contents of both sequences dpffer." << endl;
return 0;
} Code: The contents of both sequences are equal. The contents of both sequence differ. |
|
#4
| ||||
| ||||
| Re: CPP - Test whether the elements in two ranges are equal or not using function
The equal() function can be used for to Test whether the elements in two ranges are equal or not, In C++ programming. The following can be the general syntax of the equal() function in C++ language : Code: template <class InptItratr1, class InptItratr2>
bool equal ( InptItratr1 fst1, InptItratr1 lst1,
InptItratr2 fst2 ); |
|
#5
| ||||
| ||||
| CPP - Test whether the elements in two ranges are equal or not using function
The following can be the parameters of the equal() function in the C++ language : 1. fst2 : This argument can be used to the starting position of the second sequence for forward iterator. 2. fst1, lst1 : This argument can be used to the final and starting positions of the first sequence for the forward iterators. This argument of the equal() can contains the all the elements that can not be pointed by the lst1 but the elements that can be pointed by the fst1. |
|
#6
| |||
| |||
| Re: CPP - Test whether the elements in two ranges are equal or not using function PROGRAM : Code: #include <vector>
#include <algorithm>
#include <iostream>
bool twice ( int elm1, int elm2 )
{
return elm1 * 2 == elm2;
}
int main( )
{
using namespace std;
vector <int> w1, w2, w3;
vector <int>::iterator Itr1, Itr2, Itr3;
int j;
for ( j = 0 ; j <= 5 ; j++ )
{
w1.pushback( 5 * j );
}
int jj;
for ( jj = 0 ; jj <= 5 ; jj++ )
{
w2.pushback( 5 * jj );
}
int jjj;
for ( jjj = 0 ; jjj <= 5 ; jjj++ )
{
w3.pushback( 10 * jjj );
}
cout << "w1 = ( " ;
for ( Itr1 = w1.begin( ) ; Itr1 != w1.end( ) ; Itr1++ )
cout << *Itr1 << " ";
cout << ")" << endl;
cout << "w2 = ( " ;
for ( Itr2 = w2.begin( ) ; Itr2 != w2.end( ) ; Itr2++ )
cout << *Itr2 << " ";
cout << ")" << endl;
cout << "w3 = ( " ;
for ( Itr3 = w3.begin( ) ; Itr3 != w3.end( ) ; Itr3++ )
cout << *Itr3 << " ";
cout << ")" << endl;
bool c;
c = equal( w1.begin( ), w1.end( ), w2.begin( ) );
if ( c )
cout << "The vectors w1 and w2 are equal under equality."
<< endl;
else
cout << "The vectors w1 and w2 are not equal under equality."
<< endl;
bool d;
d = equal( w1.begin( ), w1.end( ), w3.begin( ) );
if ( d )
cout << "The vectors w1 and w3 are equal under equality."
<< endl;
else
cout << "The vectors w1 and w3 are not equal under equality."
<< endl;
bool e;
e = equal( w1.begin( ), w1.end( ), w3.begin( ), twice );
if ( e )
cout << "The vectors w1 and w3 are equal under twice."
<< endl;
else
cout << "The vectors w1 and w3 are not equal under twice."
<< endl;
} |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "CPP - Test whether the elements in two ranges are equal or not using function" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Windows Firewall Port Ranges? | Rschraeger | Windows Server Help | 5 | 28-10-2012 09:42 AM |
| Battlefield Play4Free: M9 pistol is equal to 15 DMG and 50cal is equal to 17 DMG | Absolete | Video Games | 7 | 02-07-2011 10:45 PM |
| ISPs with internal network IP ranges | Mega Member | Networking & Security | 3 | 17-04-2009 10:31 AM |
| Photoshop Elements and Premiere Elements go to version 7.0 | Killen | Customize Desktop | 2 | 29-08-2008 01:17 PM |
| DNS test fails with dcdiag /test:dns - TEST: Forwarders/Root hints (Forw) | MartinH | Windows Server Help | 6 | 20-06-2006 07:20 PM |