CS212: Object Oriented Analysis and Design

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

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.
SEG4110 – Advanced Software Design and Reengineering TOPIC J C++ Standard Template Library.
Data Structures Using C++ 2E
. 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.
C++ Sets and Multisets Set containers automatically sort their elements automatically. Multisets allow duplication of elements whereas sets do not. Usually,
. STL: C++ Standard Library. Main Ideas u General purpose: generic data structures & algorithms, templates u Flexibility: Allows for many combinations.
What is generic programming? The essence of the generic programming approach is concept development: systematic classification of computing components.
. The Standard C++ Library. 2 Main Ideas Purpose Flexibility Efficiency Simple & Uniform Interface.
Concept= a set of abstractions (e.g., types) (Generic Programming) Programming with Concepts defined by a set of requirements {vector, deque, list, set,
C++ Programming: Program Design Including Data Structures, Second Edition Chapter 22: Standard Template Library (STL)
Generic programming starts with algorithms. Lift Minimal requirements: works with maximal family of types Concrete algorithm: requires specific data type.
Writing Your Own STL Container Ray Lischner
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.
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)
Data Structures Using C++ 2E Chapter 13 Standard Template Library (STL) II.
C++ STL CSCI 3110.
Software Design 1.1 Tapestry classes -> STL l What’s the difference between tvector and vector  Safety and the kitchen sink What happens with t[21] on.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 22: 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:
Data Structures Using C++1 Chapter 4 Standard Template Library (STL)
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:
CS 403, Class 23Slide #1 CS Programming Languages Class 23 November 16, 2000.
Chapter 22 STL Containers §22.1 STL Basics §22.2 STL Iterators §22.3 Sequence Containers §22.4 Associative Containers §22.5 Container Adapters.
 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.
CS212: Object Oriented Analysis and Design Lecture 24: Introduction to STL.
CS 403: Programming Languages Lecture 24 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
Intro to the C++ STL Timmie Smith September 6, 2001.
Standard Template Library (STL) - Use Vector and Deque
Copyright © 2009 – Curt Hill Standard Template Library An Introduction.
STL Containers Inside Peter Sikachev Institute of Computer Graphics and Algorithms Vienna University of Technology.
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.
CSCI 383 Object-Oriented Programming & Design Lecture 25 Martin van Bommel.
CSE 332: C++ STL iterators What is an Iterator? An iterator must be able to do 2 main things –Point to the start of a range of elements (in a container)
Programming in C++ Michal Brabec Petr Malý. Standard Template Library Containers - vector, map, set, deque, list Algorithms - copy, replace, sort, find.
Chapter 17 – Templates. Function Templates u Express general form for a function u Example: template for adding two numbers Lesson 17.1 template Type.
Object-Oriented Programming (OOP) Lecture No. 42.
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.
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.
Final Exam Review COP4530.
Object-Oriented Programming (OOP) Lecture No. 41
Standard Template Library
CS212: Object Oriented Analysis and Design
C++ Programming:. Program Design Including
COP 3530 Data Structures & Algorithms
Programming with ANSI C ++
Standard Template Library
Standard Template Library (STL)
Starting Out with C++ Early Objects Eighth Edition
Prof. Michael Neary Lecture 7: The STL Prof. Michael Neary
Programming with Concepts
Chapter 22: Standard Template Library (STL)
Miscellaneous Stuff Which there wasn’t enough time to cover
Final Exam Review COP4530.
Generic Programming Karl Lieberherr 12/1/2018 Generic Programming.
Containers, Iterators, Algorithms, Thrust
Standard Template Library
Copyright © – Curt Hill STL List Details Copyright © – Curt Hill.
Jim Fawcett CSE687 – Object Oriented Design Spring 2002
Some Definitions vector, string, deque, and list are standard sequence containers. set, multiset, map, multimap, unordered_set, unordered_multiset, unordered_map.
A dictionary lookup mechanism
Standard Template Library
Presentation transcript:

CS212: Object Oriented Analysis and Design Iterators and Algorithms

STL Components STL Iterator Algorithm Container

For assigning an algorithm to a container Plug compatible For assigning an algorithm to a container Some algorithms are good with some data structure Input Output

Object Oriented Analysis and Design (CS 212) Storing objects Accessing objects Manipulate the objects Container(s) Iterator(s) Algorithm Container classes Iterators Generic Algorithms Random Access +=, -=,+,-,>,<,>=,<= random_shuffle(), sort(), … Vector, deque Bidirectional ++,-- reverse(), partition(), … List, Multiset, Set, Multimap, Map Forward ++,!=,==,* accumulate(), copy(), count(), … Input Output Object Oriented Analysis and Design (CS 212)

Major categories of STL

Accumulate

Input Iterator Reads from a input sequence (built-in type, user-defined type, stream) It refers to a family of types ++, *, == operator to be defined for the type on which to iterate

Output iterators Allow us to write values to a sequence Do not guarantee that we can read from the sequence ==, != need not be defined for the output iterator

Forward iterators Input operator writes value to a sequence, output iterator reads from a sequence Forward iterator allows both reading, writing and traverse in one direction It is possible to save a forward iterator Later start from the same position (multipass algorithm)

Forward iterator One example where forward iterator is used, STL replace

Bidirectional Iterator Forward iterators allow traverse in a single direction Bidirectional iterator allows traversal in either direction Both prefix and postfix version of operator-- is required STL reverse algorithm can be used

Using Iterators Pointer like objects in STL STL algorithms uses them to traverse through the container An array can be accessed either through subscripting or through a pointer The members of a vector using subscripting or through the use of an iterator Demonstration

Insert and Delete Insert element at a given location Delete element from a given location Demonstration

Storing Class Objects Vectors are not limited for built-in types Can store any type of objects (user defined types) It must also define the < and == operations Demonstration

Random access iterator To support algorithms with greater constraints Any position in a sequence be reachable from any other in constant time Similar to bidirectional iterator, plus Addition and subtraction of an integer Use of Offset Bi-directional “Big-jumps” Iterator subtraction Comparison operator >, >=, < , <=

STL Iterator Hierarchy Why it is useful to classify iterators into categories Classification is an iterator hierarchy Iterator categories are used in the specification of the container and the algorithm e.g. List provides bidirectional iterators, and find requires input iterator. So, find can be used with lists Input, Output Forward Bidirectional Random Access What about sort??

Insert Iterator Insert iterators are special output iterators Prevents overwrite at a particular location Insert new elements at a specific position in the container The container needs to have an insert member function