Skip to content

Instantly share code, notes, and snippets.

@hpcx82
Created November 29, 2013 14:22
Show Gist options
  • Save hpcx82/7706354 to your computer and use it in GitHub Desktop.
Save hpcx82/7706354 to your computer and use it in GitHub Desktop.
// StlAlgo.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <vector>
#include <array>
#include <algorithm>
#include <iterator> // ostream_iterator
#include <iostream>
using namespace std;
void bound_algorithms()
{
array<int, 9> arr = {11, 20, 4, 5, 5, 5, 7, 9, 1};
// sort(arr.begin(), arr.end(), [](int x, int y) {return x > y;});
sort(arr.begin(), arr.end());
ostream_iterator<int> console(cout, ", ");
//1, 4, 5, 5, 5, 7, 9, 11, 20,
copy(arr.begin(), arr.end(), console);
cout << endl;
//1, 4, - iterator point to the lower bound of a value in the array
auto it_low = lower_bound(arr.begin(), arr.end(), 5);
copy(arr.begin(), it_low, console);
cout << endl;
//5, 5, 5,
auto it_eq = equal_range(arr.begin(), arr.end(), 5);
copy(it_eq.first, it_eq.second, console);
cout << endl;
//1, 4, 5, 5, 5, - iterator point to the upper bound of a value in the array
auto it_up = upper_bound(arr.begin(), arr.end(), 5);
copy(arr.begin(), it_up, console);
cout << endl;
}
int _tmain(int argc, _TCHAR* argv[])
{
bound_algorithms();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment