C++/List/list compare

Материал из C\C++ эксперт
Перейти к: навигация, поиск

Use equal function to compare values in a list againt vector

<source lang="cpp">

  1. include <algorithm>
  2. include <iostream>
  3. include <list>
  4. include <vector>

using namespace std; int main( ) {

  short v[] = { 1, 2, 3, 4, 5, 6 };
  vector<short> v1( v,v + sizeof( v ) / sizeof( v[0] ) );
  list<short> l( v1.begin(), v1.end() );
  
  if( v1.size() == l.size() && equal( v1.begin(), v1.end(), l.begin() ) )
     cout << "The vector and list are equal" << endl;
  else
     cout << "The vector and list are not equal" << endl;

}


 </source>