-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSTL_algorithms.cpp
42 lines (29 loc) · 896 Bytes
/
STL_algorithms.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
#include <algorithm>
using namespace std;
// C++ STL (Standard Template Library) is a powerful set
// of C++ template classes to provide general-purpose classes
// and functions with templates that implement many popular
// and commonly used algorithms and data structures like
// vectors, lists, queues, and stacks.
// STL has: Containers. Algorithms. Iterators.
void print(int arr[], int size)
{
for (int i; i < size; ++i)
{
cout << arr[i] << "-";
}
}
int main()
{
int arr[] = {3, 5, 8, 2, 4};
int size = sizeof(arr) / sizeof(int);
print(arr, size);
sort(arr, arr + size);
print(arr, size);
cout << "binary_search result: " << binary_search(arr, arr + size, 4) << endl;
sort(arr, arr + size);
print(arr, size);
cout << "binary_search result: " << binary_search(arr, arr + size, 8) << endl;
return 1;
}