Presentation is loading. Please wait.

Presentation is loading. Please wait.

Standard Template Library Jyh-Shing Roger Jang ( 張智星 ) CSIE Dept, National Taiwan University.

Similar presentations


Presentation on theme: "Standard Template Library Jyh-Shing Roger Jang ( 張智星 ) CSIE Dept, National Taiwan University."— Presentation transcript:

1 Standard Template Library Jyh-Shing Roger Jang ( 張智星 ) CSIE Dept, National Taiwan University

2 2 Intro. to Standard Template Library Standard Template Library (STL) A collection of useful classes for common data structures STL provides data structures for standard containers Each type of STL can store objects of any kinds. FAQ for STL

3 3 Advantage of STL vectors STL vectors are superior to standard C++ arrays Element access Index operator: vec[i] “at” member function: vec.at(i) (This perform range checking and generates an error exception if the index is out of bounds.) Dynamic growth of arrays Memory are automatic allocated (and reallocated) Almost no memory leak No need to delete/free memory explicitly A number of methods for common array operations Disadvantages of STL vectors Not as efficient as standard C/C++ arrays Comprehensive comparison

4 4 STL Vectors and Algorithms #include

5 5 Examples of STL Vectors Some example of STL vectors is here: Memory of STL vectors is allocated implicitly You can reserve a vector of size n by “vec.reserve(n)”. You can keep on pushing back to go beyond n. Once it go explodes, a new size of 1.5*n is allocated implicitly.

6 6 Resources & References Member functions of STL vectors Algorithms that can be used for STL vectors A comprehensive site for STL Check the list before you go! Don’t reinvent the wheel!


Download ppt "Standard Template Library Jyh-Shing Roger Jang ( 張智星 ) CSIE Dept, National Taiwan University."

Similar presentations


Ads by Google