Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

Comparaison lexicographique sur un tableau de ‘int’

 iterator
{filelink=15204}

#include <algorithm>
#include <iostream>
#include <ostream>
using namespace std;
 
  int a[] = { 1, 10, 3, 42 };
 
  int b[] = { 1, 10, 42, 3 };
 
  int c[] = { 1, 10, 3 };
 
int main(  )
 
{
 
  cout<<"a: ";
  copy(a,a+4,ostream_iterator<int>(cout," "));
  cout<<endl;
 
  cout<<"b: ";
  copy(b,b+4,ostream_iterator<int>(cout," "));
  cout<<endl;
 
  cout<<"c: ";
  copy(c,c+3,ostream_iterator<int>(cout," "));
  cout<<endl;
 
  cout << boolalpha;
 
  cout <<"(a, a+4, b, b+4): "
	    << lexicographical_compare(a, a+4, b, b+4)<<endl;
 
  cout <<"(a, a+4, c, c+3): "
	   << lexicographical_compare(a, a+4, c, c+2)<<endl; 
 
  cout <<"(a, a+4, a, a+4): "
	   << lexicographical_compare(a, a+4, a, a+4)<<endl;
 
  cout <<"(c, c+3, b, b+4): "
	   << lexicographical_compare(c, c+2, b, b+4)<<endl; 
 
  return 0;
 
}

No comments yet.

Leave a Comment