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

Slides:



Advertisements
Similar presentations
Chapter 19 Vectors, templates, and exceptions Bjarne Stroustrup
Advertisements

Chapter 18 Vectors and Arrays
Chapter 7 Constructors and Other Tools. Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 7-2 Learning Objectives Constructors Definitions.
Etter/Ingber Arrays and Matrices. Etter/Ingber One-Dimensional Arrays 4 An array is an indexed data structure 4 All variables stored in an array are of.
1.00 Lecture 37 A Brief Look at C++: A Guide to Reading C++ Programs.
1 Joe Meehean. Ordered collection of items Not necessarily sorted 0-index (first item is item 0) Abstraction 2 Item 0 Item 1 Item 2 … Item N.
SEG4110 – Advanced Software Design and Reengineering TOPIC J C++ Standard Template Library.
Brown Bag #2 Advanced C++. Topics  Templates  Standard Template Library (STL)  Pointers and Smart Pointers  Exceptions  Lambda Expressions  Tips.
Huffman Coding An implementation using C++ STL (part of the material is due to the work of Mark Nelson, Dr. Dobb’s Journal, January 1996)
Chapter 18 Vectors and Arrays John Keyser’s Modification of Slides by Bjarne Stroustrup
Various languages….  Could affect performance  Could affect reliability  Could affect language choice.
Beginning C++ Through Game Programming, Second Edition
Shallow Copy Jyh-Shing Roger Jang ( 張智星 ) CSIE Dept, National Taiwan University.
Lecture 3 Feb 4 summary of last week’s topics and review questions (handout) Today’s goals: Chapter 1 overview (sections 1.4 to 1.6) c++ classes constructors,
Binary Search Visualization i j.
Standard Containers: Vectors
Slides prepared by Rose Williams, Binghamton University Chapter 14 Generics and the ArrayList Class.
C++ for Engineers and Scientists Third Edition
Binomial Heaps Jyh-Shing Roger Jang ( 張智星 ) CSIE Dept, National Taiwan University.
Data Structures Using C++ 2E
Quick Sort Instructor : Prof. Jyh-Shing Roger Jang Designer : Shao-Huan Wang The ideas are reference to the textbook “Fundamentals of Data Structures.
Comp 245 Data Structures Linked Lists. An Array Based List Usually is statically allocated; may not use memory efficiently Direct access to data; faster.
C++ STL CSCI 3110.
C++ for Engineers and Scientists Second Edition Chapter 11 Arrays.
Singly Linked Lists Jyh-Shing Roger Jang ( 張智星 ) CSIE Dept, National Taiwan University 1.
Pointers in C++. 7a-2 Pointers "pointer" is a basic type like int or double value of a pointer variable contains the location, or address in memory, of.
Sorting Algorithms Jyh-Shing Roger Jang ( 張智星 ) CSIE Dept, National Taiwan University.
Python Arrays. An array is a variable that stores a collection of things, like a list. For example a list of peoples names. We can access the different.
Standard Template Library The Standard Template Library was recently added to standard C++. –The STL contains generic template classes. –The STL permits.
Sparse Vectors & Matrices Jyh-Shing Roger Jang ( 張智星 ) CSIE Dept, National Taiwan University.
Binary Search Jyh-Shing Roger Jang ( 張智星 ) CSIE Dept, National Taiwan University.
CS212: Object Oriented Analysis and Design Lecture 24: Introduction to STL.
Concordia University Department of Computer Science and Software Engineering Click to edit Master title style ADVANCED PROGRAM DESIGN WITH C++ Static arrays.
Intro to the C++ STL Timmie Smith September 6, 2001.
Template is a declaration (similar to class declaration), which deals with generic types. Templates are evaluated to produce concrete classes when a template-base.
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
STL CSSE 250 Susan Reeder. What is the STL? Standard Template Library Standard C++ Library is an extensible framework which contains components for Language.
STL: Maps Jyh-Shing Roger Jang ( 張智星 ) CSIE Dept, National Taiwan University.
Introduction The STL is a complex piece of software engineering that uses some of C++'s most sophisticated features STL provides an incredible amount.
Chapter 7 Constructors and Other Tools Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
Glenn Stevenson CSIS 113A MSJC CSIS 123A Lecture 3 Vectors.
Maximum Likelihood Estimate Jyh-Shing Roger Jang ( 張智星 ) CSIE Dept, National Taiwan University.
Chapter 17 – Templates. Function Templates u Express general form for a function u Example: template for adding two numbers Lesson 17.1 template Type.
Chapter  Array-like data structures  ArrayList  Queue  Stack  Hashtable  SortedList  Offer programming convenience for specific access.
Unit VI.  C++ templates are a powerful mechanism for code reuse, as they enable the programmer to write code (classes as well as functions) that behaves.
Simulation of Stock Trading J.-S. Roger Jang ( 張智星 ) MIR Lab, CSIE Dept. National Taiwan University.
Linear Classifiers (LC) J.-S. Roger Jang ( 張智星 ) MIR Lab, CSIE Dept. National Taiwan University.
From C to C++ Jyh-Shing Roger Jang ( 張智星 ) CSIE Dept, National Taiwan University.
Copyright © 2002 Pearson Education, Inc. Slide 1.
Copyright © 2002 Pearson Education, Inc. Slide 1.
From C to C++ Jyh-Shing Roger Jang (張智星)
Standard Template Library
Programming with ANSI C ++
Collections Intro What is the STL? Templates, collections, & iterators
Object Oriented Programming COP3330 / CGS5409
Vectors.
7. 11 Introduction to C++ Standard Library Class Template vector (Cont
Constructors and Other Tools
Standard Template Library Model
Vectors.
Circularly Linked Lists and List Reversal
Queues Jyh-Shing Roger Jang (張智星)
Insertion Sort Jyh-Shing Roger Jang (張智星)
Examples of Time Complexity
Selection Algorithm Jyh-Shing Roger Jang (張智星)
Collections Intro What is the STL? Templates, collections, & iterators
Game Trees and Minimax Algorithm
Sorting Algorithms Jyh-Shing Roger Jang (張智星)
Storing Game Entries in an Array
Lecture 3 – Data collection List ADT
Presentation transcript:

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

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 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 STL Vectors and Algorithms #include

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 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!