Lecture05 - Lecture 5 The Standard Template Library...

Info icon This preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
Lecture 5: The Standard Template Library
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Overview of STL Toolbox of data structures and algorithms Template library, so very flexible Made up of Containers: hold other objects e.g. vector, list, set, map Iterators: allow us to access/manipulate containers Algorithms
Image of page 2
Example Taken from SGI STL documentation http://www.sgi.com/tech/stl/ vector<int> v(3); v[0] = 7; v[1] = v[0] + 3; v[2] = v[0] + v[1]; reverse(v.begin(), v.end());
Image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
STL Iterators Like pointers (pointers are iterators, too) begin() and end() are member functions of every container Return iterators to the container vector<int> v(3); vector<int>::iterator itr1 = v.begin(); begin() returns iterator accessing first item end() returns iterator accessing one position PAST last item
Image of page 4
More on iterators Operations on iterators itr++ *itr itr1 == itr2 itr1 != itr2 Bidirectional iterator also has --itr Random access iterator supports itr + 5 itr1 – itr2 Also have const iterators vector<int>::const_iterator for accessing non-modifiable containers Reverse iterators
Image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern