Comparison Algorithms : list « List « C++

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;

  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);

Related examples in the same category

1.Instantiating an STL List of Integers
2.Use generic list to create a list of chars
3.Use generic list to create list of strings
4.Store class objects in a listStore class objects in a list
5.Store class objects with overloaded operators in a list.
6.Use std::copy to print all elements in a list
7.Pass list to a function
8.Uses ostream_iterator and copy algorithm to output list elements
9.Add elements in a multiset to a list
10.access list
11.Add elements in a set to a list
12.Merge two lists.Merge two lists.
13.Using the list as a container for double value