Standard Template Library Model

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

Chapter 21 The STL (maps and algorithms) Bjarne Stroustrup
Chapter 20 The STL (containers, iterators, and algorithms)
Copyright © 2002 Pearson Education, Inc. Slide 1.
Chapter 19 Standard Template Library. Copyright © 2006 Pearson Addison-Wesley. All rights reserved Learning Objectives Iterators Constant and mutable.
Thrust & Curand Dr. Bo Yuan
Data Structures Using C++
SEG4110 – Advanced Software Design and Reengineering TOPIC J C++ Standard Template Library.
Chapter 20 The STL (containers, iterators, and algorithms) John Keyser’s Modifications of Slides by Bjarne Stroustrup
. STL: C++ Standard Library (continued). STL Iterators u Iterators are allow to traverse sequences u Methods  operator*  operator->  operator++, and.
Multimaps. Resources -- web For each new class, browse its methods These sites are richly linked, and contain indexes, examples, documents and other resources.
Beginning C++ Through Game Programming, Second Edition
More on the STL vector list stack queue priority_queue.
C++ Programming: Program Design Including Data Structures, Second Edition Chapter 22: Standard Template Library (STL)
CMSC 202 Lesson 24 Iterators and STL Containers. Warmup Write the class definition for the templated Bag class – A bag has: Random insertion Random removal.
Rossella Lau Lecture 1, DCO20105, Semester A, DCO Data structures and algorithms  Lecture 1: Introduction What this course is about:  Data.
Rossella Lau Lecture 12, DCO10105, Semester B, DCO10105 Object-Oriented Programming and Design  Lecture 12: An Introduction to the STL  Basic.
C++ / G4MICE Course Session 3 Introduction to Classes Pointers and References Makefiles Standard Template Library.
Data Structures Using C++ 2E
C++ How to Program, 8/e © by Pearson Education, Inc. All Rights Reserved.
PRESENTED BY: RAJKRISHNADEEPAK.VUYYURU SWAMYCHANDAN.DONDAPATI VINESHKUMARREDDY.LANKA RAJSEKHARTIRUMALA KANDURI ALAN.
Comp 245 Data Structures Linked Lists. An Array Based List Usually is statically allocated; may not use memory efficiently Direct access to data; faster.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Standard Template Library (STL)
COP 3530 Data Structures & Algorithms Discussion Session 3.
CSCE 121: Introduction to Program Design and Concepts, Honors J. Michael Moore Spring 2015 Set 19: The STL: Containers and Iterators 1.
Standard Template Library The Standard Template Library was recently added to standard C++. –The STL contains generic template classes. –The STL permits.
1 Iterators Good reference site:
 2003 Prentice Hall, Inc. All rights reserved.m ECE 2552 Dr. Këpuska based on Dr. S. Kozaitis Summer Chapter 15 - Class string and String Stream.
1 Chapter 1 C++ Templates Sections 1.6 and Templates Type-independent patterns that can work with multiple data types –Generic programming –Code.
Intro to the C++ STL Timmie Smith September 6, 2001.
Data Structures Using C++1 Chapter 5 Linked Lists.
Copyright © 2009 – Curt Hill Standard Template Library An Introduction.
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.
Chapter 17 – Templates. Function Templates u Express general form for a function u Example: template for adding two numbers Lesson 17.1 template Type.
CSCE Introduction to Program Design and Concepts J. Michael Moore Spring 2015 Set 6: Miscellaneous 1 Based on slides created by Bjarne Stroustrup.
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.
Regarding homework 9 Many low grades
Programming with ANSI C ++
Standard Template Library
C++ Standard Library.
Standard Template Library (STL)
STL Common tools for C++.
Prof. Michael Neary Lecture 7: The STL Prof. Michael Neary
Anatomy of a Function Part 2
Sorting CSCE 121 J. Michael Moore
Introduction to the Standard Template Library
IO Overview CSCE 121 J. Michael Moore
Final Exam Review COP4530.
Manipulators CSCE 121 J. Michael Moore
Array & Pointers CSCE 121 J. Michael Moore.
priority_queue<T>
Functions Overview CSCE 121 J. Michael Moore
Anatomy of Templates CSCE 121 J. Michael Moore
Anatomy of a Function Part 3
CS212: Object Oriented Analysis and Design
Standard Template Library Find
Containers and the Standard Template Library (STL)
Data structures and algorithms
ITERATORS Acknowledgement: THE Slides are Prepared FROM SLIDES PROVIDED By NANCY M. AMATO AND Jory Denny.
STL: Traversing a Vector
Iterators and STL Containers
CSCE 121 – Spring 2016 Professor J. Michael Moore
Guidelines for Writing Functions
STL and Example.
STL List.
the Standard Template Library
An Introduction to STL.
Some Definitions vector, string, deque, and list are standard sequence containers. set, multiset, map, multimap, unordered_set, unordered_multiset, unordered_map.
STL List.
Presentation transcript:

Standard Template Library Model CSCE 121 Slides adapted from J. Michael Moore Based on slides created by Bjarne Stroustrup and Jennifer Welch

Basic STL Model iterators Algorithms sort, find, search, copy, … Containers vector, list, map, unordered_map, … Separation of concerns Algorithms manipulate data, but don’t know about containers Containers store data, but don’t know about algorithms Algorithms and containers interact through iterators Each container has its own iterator types iterators

Iterators A single iterator is essentially the position of an element A pair of iterators defines a sequence the beginning (points to first element, if any) the end (points to the one-beyond-the-last element) … begin: end:

Iterators … begin: Supports the “iterator operations”: end: Supports the “iterator operations”: Go to next element: ++ Get value: * Check if two iterators point to same element: == Frequently a pointer type, but not necessarily Some iterators support more operations (--, +, [ ] )

One-Past-The-Last An iterator point to (refers to, denotes) an element of a sequence The end of the sequence is “one past the last element”, not the last element! Reason is to elegantly represent an empty sequence One-past-the last element is not an element you can compare an iterator pointing to it but you cannot dereference it (get its value) 1 2 3 the end: An empty sequence: begin: end: some iterator:

Containers Hold sequences in different ways vector 1 2 3

Containers Hold sequences in different ways list (doubly-linked) 1 2

Containers Hold sequences in different ways set (a kind of tree) 6 2 7 1 5 3 4