Standard Template Library. Homework List HW will be posted on webpage Due Nov 15.

Slides:



Advertisements
Similar presentations
M The University Of Michigan Andrew M. Morgan EECS Lecture 22 Savitch Ch. 16 Intro To Standard Template Library STL Container Classes STL Iterators.
Advertisements

Hold data and provide access to it. Random-access containers: -Allow accessing any element by index -arrays, vectors Sequential containers: -Allow accessing.
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.
Object Oriented Programming Lect. Dr. Daniel POP Universitatea de Vest din Timişoara Facultatea de Matematică şi Informatică.
Vectors, lists and queues
Multimaps. Resources -- web For each new class, browse its methods These sites are richly linked, and contain indexes, examples, documents and other resources.
C++ Templates. What is a template? Templates are type-generic versions of functions and/or classes Template functions and template classes can be used.
Beginning C++ Through Game Programming, Second Edition
COMP 171 Data Structures and Algorithms Tutorial 1 Template and STL.
More on the STL vector list stack queue priority_queue.
OOP Etgar 2008 – Recitation 101 Object Oriented Programming Etgar 2008 Recitation 10.
Standard Template Library (STL) Overview – Part 1 Yngvi Bjornsson.
Prof. amr Goneid, AUC1 CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 11a. The Vector Class.
Templates and the STL.
Writing Your Own STL Container Ray Lischner
CSIS 123A Lecture 12 Templates. Introduction  C++ templates  Allow very ‘general’ definitions for functions and classes  Type names are ‘parameters’
Sorting and Vectors Mechanism for representing lists JPC and JWD © 2002 McGraw-Hill, Inc. Modified by S. Sudarshan.
Standard Template Library Programming paradigm: generic programming the decomposition of programs into components which may be developed separately and.
Dr. Yingwu Zhu STL Vector and Iterators. STL (Standard Template Library) 6:14:43 AM 2 A library of class and function templates Components: 1. Containers:
STL Standard Template Library ● Good reference book: – The C++ Standard Library ● A Tutorial and Reference ● by Nicolai M. Josuttis ● 1999 – Addison Wesley.
STL !!!generic programming!!! Anar Manafov
Data Structures Using C++ 2E
1 Chapter 3 Lists, Stacks, and Queues Abstract Data Types, Vectors Sections 3.1, 3.2, 3.3, 3.4 Abstract Data Types (ADT) Iterators Implementation of Vector.
Containers Overview and Class Vector
CNS  Sequences  vector,deque,list,(string),forward_list  Container Adapters  queue, stack, priority_queue  Associative Containers  set, unordered_set.
DATA STRUCTURES AND ALGORITHMS Lecture Notes 12 Prepared by İnanç TAHRALI.
PRESENTED BY: RAJKRISHNADEEPAK.VUYYURU SWAMYCHANDAN.DONDAPATI VINESHKUMARREDDY.LANKA RAJSEKHARTIRUMALA KANDURI ALAN.
Introduction to STL and the vector container class CS342 Data Structures Based on Ford & Topp.
Generic Programming Using the C++ Standard Template Library.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Standard Template Library (STL)
CSE 332: C++ STL containers Review: C++ Standard Template Library (STL) The STL is a collection of related software elements –Containers Data structures:
Templates code reuse - inheritance - template classes template classes - a class that is not data-type specific - eg. a class of Array of any type - intArray,
Friends & Standard Template Library CSCI3110 Advanced Data Structures Lecturer: Dr. Carroll and Nan Chen.
Standard Template Library The Standard Template Library was recently added to standard C++. –The STL contains generic template classes. –The STL permits.
Introduction to the Standard Template Library (STL) A container class holds a number of similar objects. Examples: –Vector –List –Stack –Queue –Set –Map.
Iterator for linked-list traversal, Template & STL COMP171 Fall 2005.
1 Chapter 1 C++ Templates Sections 1.6 and Templates Type-independent patterns that can work with multiple data types –Generic programming –Code.
Lecture 7 : Intro. to STL (Standard Template Library)
Computer Science and Software Engineering University of Wisconsin - Platteville 11.Standard Template Library Yan Shi CS/SE 2630 Lecture Notes.
Data Structures for Midterm 2. C++ Data Structure Runtimes.
A gentle introduction to the standard template library (STL) Some references:
STL – Standard Template Library L. Grewe. 2 Goals Lots of important algorithms, data structures in CS using Templates. is a software library partially.
The Standard Template Library Container Classes Version 1.0.
Starting Out with C++, 3 rd Edition Introduction to the STL vector The Standard Template Library (or STL) is a collection of data types and algorithms.
Introduction The STL is a complex piece of software engineering that uses some of C++'s most sophisticated features STL provides an incredible amount.
C++ Review STL CONTAINERS.
1 Chapter 3 Lists, Stacks, and Queues Reading: Sections 3.1, 3.2, 3.3, 3.4 Abstract Data Types (ADT) Iterators Implementation of Vector.
CSCI 383 Object-Oriented Programming & Design Lecture 25 Martin van Bommel.
1 The Standard Template Library Drozdek Section 3.7.
Lecture 7.  There are 2 types of libraries used by standard C++ The C standard library (math.h) and C++ The C++ standard template library  Allows us.
1 The Standard Template Library The STL is a collection of Container classes These are class templates for containers. A container is an object that stores.
Object-Oriented Programming (OOP) Lecture No. 41
Vectors Holds a set of elements, like an array
CSCE 210 Data Structures and Algorithms
Standard Template Library (STL)
C++ Programming Standard Library
Prof. Michael Neary Lecture 7: The STL Prof. Michael Neary
Object Oriented Programming COP3330 / CGS5409
C++ STL Vector Container
priority_queue<T>
Copyright © – Curt Hill STL List Details Copyright © – Curt Hill.
Lecture 8 : Intro. to STL (Standard Template Library)
STL Библиотека стандартных шаблонов
STL (Standard Template Library)
Standard Template Library
C++ Programming: chapter 10 – STL
An Introduction to STL.
Chapter 3 Lists, Stacks, and Queues
Presentation transcript:

Standard Template Library

Homework List HW will be posted on webpage Due Nov 15

The STL includes: Containers – a data structure which holds arbitrary data type Iterators – way of ‘browsing’ through a container Algorithms – operations which can be performed on any container (where it makes sense)

Containers vector list deque (double-ended queue) set and multiset map and multimap

vector Much like an array Accessible with [] Provides constant-time random access Dynamically resizable May be of any type.

list Changes size as elements are inserted or deleted May be of any type.

list syntax #include using namespace std; void aFunc() { list lst; lst.push_back(7.0); }

Some list methods Since list is a class, it has methods –push_back() –pop_back() –front() –back() –empty() –clear() –size() –resize() –capacity() See

Iterator Iterators are a convenient way to ‘browse’ Every container offers a object.start() Every container offers an object.end() Every iterator supports ++ and - - (no matter what the structure of the container)

List organization From any car in the train you may go to the preceding or succeeding one Use ++ or - - operation on the iterator

Lists #include A list is like a freight train Cars in sequence, starting with 0 Each car is a container for a type of data – e.g. an int, a float, a object

Examine the elements of a list #include using namespace std; int main() { list lst; list ::iterator lp; for (lp = lst.begin(); lp != lst.end(); ++lp) { // do something here } return 0; }

Algorithms You must include the header #include using namespace std;

Algorithms Provides standard algorithms like sort and swap on any kind of data in the container, provided …

Algorithms Provides standard algorithms like sort and swap on any kind of data in the container, provided … That prerequisites are defined (the < operator for sort)

Sort algorithm example #include using namespace std; int main() { list lst; for (int i = 0; i < 5; ++i) { int aNum = rand() % 100; lst.push_back(aNum); } lst.sort(); return 0; }