Week 4 Day 1 - The Standard Library & Ranges
Channel:
Subscribers:
2,650
Published on ● Video Link: https://www.youtube.com/watch?v=l8WX2WRMPd4
Today we talked about the various things in the standard library, and how the concept of ranges plays in it it. A range is two iterators (iterators are kinda like a pointer) that point to the beginning and ONE PAST the end of the elements in the data structure that you want to do the function on. If you want to do the whole data structure, you use begin and end, like this:
sort(vec.begin(),vec.end()); (End() points one past the end of the vector.)
You can add ints to an iterator to create ranges like this:
random_shuffle(vec.begin(),vec.begin()+10); //Shuffles the first 10 elements of the vector
(Obviously you want to bounds check before just adding 10 to .begin().)
Other Videos By Bill Kerney
Tags:
csci 41
data structures
std
standard library
ranges