Mega Code Archive

 
Categories / C++ / List
 

Comparison Algorithms

#include <algorithm> #include <vector> #include <list> #include <iostream> using namespace std; int main(int argc, char** argv) {   vector<int> myVector;   list<int> myList;   myVector.push_back(1);   myVector.push_back(2);   myVector.push_back(3);      myList.push_back(1);   myList.push_back(2);   myList.push_back(3);      if (myList.size() < myVector.size()) {     cout << "Sorry, the list is not long enough.\n";     return (0);   }   if (equal(myVector.begin(), myVector.end(), myList.begin())) {     cout << "The two containers have equal elements\n";   }    if (lexicographical_compare(myVector.begin(), myVector.end(), myList.begin(),myList.end())) {     cout << "The vector is lexicographically first.\n";   } else {     cout << "The list is lexicographically first.\n";   }   return (0); }