The purpose of this lab is to learn how to use the STL algorithms. For this lab, you will use the STL algorithms on the STL vector class.
To use the STL algorithms and the vector class, you will need the following headers in your lab5.cpp file:
#include <vector> #include <algorithm> using namespace std;This will give you access to the algorithms and the vector class. The vector class contains iterators and the standard iterator functions
begin()
and end()
. For example, the following code
snippet from page 565 of the book will sort a vector using the STL
sort
algorithm:
int ints[] = {555, 33, 444, 22, 222, 777, 1, 66}; vector<int> v(ints, ints + 5); // Use only the first 5 elements of ints sort(v.begin(), v.end());Create a main program that does the following sequentially (no menus needed):
find
function. Print "Integer was found" if found and
"Integer was not found" if not found.
sort
algorithm and print the
sorted vector to the screen.
unique
and print the results to the screen.
reverse
algorithm and
print the reversed values to the screen.
random_shuffle
and print the results to the screen.