// set example
//
// - a set is an ordered associative container
// - no matter when you insert an item, it is ordered internally
// - therefore, if you use an iterate to traverse the set, it is ordered
// - see http://www.cppreference.com/cppset.html

#include <set>
#include <iostream>

using namespace std;

int main()
{
  set<int> s; // create a set of integers

  s.insert(5); // 5
  s.insert(4); // 4 5
  s.insert(7); // 4 5 7
  s.insert(9); // 4 5 7 9
  s.insert(2); // 2 4 5 7 9
  s.insert(3); // 2 3 4 5 7 9

  cout << "set s has " << s.size() << " elements" << endl;

  // note: set also has a reverse_iterator as well
  cout << "set s has elements ";
  for (set<int>::const_iterator sit = s.begin(); sit != s.end(); sit++) {
    cout << *sit << " ";
  }
  cout << endl;

  set<int>::const_iterator fsit0 = s.find(4); // try to find 4
  if (fsit0 != s.end()) { // if element not found, s.end() is returned
    cout << "set s has element 4" << endl;
  } else {
    cout << "set s does not have element 4" << endl;
  }

  set<int>::const_iterator fsit1 = s.find(8); // try to find 8
  if (fsit1 != s.end()) { // if element not found, s.end() is returned
    cout << "set s has element 8" << endl;
  } else {
    cout << "set s does not have element 8" << endl;
  }

  return 0;
}
