Standard Template Library

Slides:



Advertisements
Similar presentations
Copyright © 2002 Pearson Education, Inc. Slide 1.
Advertisements

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.
. STL: C++ Standard Library (continued). STL Iterators u Iterators are allow to traverse sequences u Methods  operator*  operator->  operator++, and.
. The Standard C++ Library. 2 Main Ideas Purpose Flexibility Efficiency Simple & Uniform Interface.
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.
Prof. amr Goneid, AUC1 CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 11a. The Vector Class.
Rossella Lau Lecture 12, DCO10105, Semester B, DCO10105 Object-Oriented Programming and Design  Lecture 12: An Introduction to the STL  Basic.
CSE 332: C++ Algorithms II From Last Time: Search with Generic Iterators Third generalization: separate iterator type parameter We arrive at the find algorithm.
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.
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)
CSE 332: C++ STL containers Review: C++ Standard Template Library (STL) The STL is a collection of related software elements –Containers Data structures:
1. The term STL stands for ? a) Simple Template Library b) Static Template Library c) Single Type Based Library d) Standard Template Library Answer : d.
Chapter 9: Part 2: Vectors + Maps and STL Overview JPC and JWD © 2002 McGraw-Hill, Inc. Modified by S. Sudarshan.
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:
 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.
ITERATORS. Iterator An iterator in C++ is a concept that refines the iterator design pattern into a specific set of behaviors that work well with the.
Templates “Generic Programming” ECE Templates A way to write code once that works for many different types of variables –float, int, char, string,
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.
STL CSSE 250 Susan Reeder. What is the STL? Standard Template Library Standard C++ Library is an extensible framework which contains components for Language.
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 1 C++ Templates (Sections 1.6, 1.7). Templates Type-independent patterns that can work with multiple data types. Function Templates  These define.
Glenn Stevenson CSIS 113A MSJC CSIS 123A Lecture 3 Vectors.
Programming in C++ Michal Brabec Petr Malý. Standard Template Library Containers - vector, map, set, deque, list Algorithms - copy, replace, sort, find.
1 Chapter 1 C++ Templates Readings: Sections 1.6 and 1.7.
Chapter 17 – Templates. Function Templates u Express general form for a function u Example: template for adding two numbers Lesson 17.1 template Type.
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.
C++ Standard Template Library
Sorting Algorithms Sections 7.1 to 7.4.
CS212: Object Oriented Analysis and Design
“Generic Programming” ECE 297
C++ Programming:. Program Design Including
Concepts of Programming Languages
COP 3530 Data Structures & Algorithms
Programming with ANSI C ++
Standard Template Library
CSCE 210 Data Structures and Algorithms
C++ Standard Library.
Standard Template Library
Standard Template Library (STL)
Starting Out with C++ Early Objects Eighth Edition
Collections Intro What is the STL? Templates, collections, & iterators
Prof. Michael Neary Lecture 7: The STL Prof. Michael Neary
Chapter 22: Standard Template Library (STL)
abstracting away the data structure
Vectors.
A Sorted, Unique Key Container
CS212: Object Oriented Analysis and Design
Generic Programming Karl Lieberherr 12/1/2018 Generic Programming.
7. 11 Introduction to C++ Standard Library Class Template vector (Cont
Standard Template Library Find
Elements are always copied when they are put into a container
Standard Template Library Model
ITERATORS Acknowledgement: THE Slides are Prepared FROM SLIDES PROVIDED By NANCY M. AMATO AND Jory Denny.
The Standard Template Library
Iterators and STL Containers
Collections Intro What is the STL? Templates, collections, & iterators
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.
A dictionary lookup mechanism
Presentation transcript:

Standard Template Library C++ Review Standard Template Library CSCE 221H Texas A&M University 1 1

Outline Standard Template Library Containers Iterators Algorithms Summary

Standard Template Library A general purpose library of data structures (containers) and algorithms communicating through iterators. Plug each piece together and use in different applications. container generic algorithm sort vector iterator #include <vector> #include <algorithm> int main(){ int myArray[4]={2, 8, 5, 3}; std::vector<int> v(myArray, myArray+4); std::sort(v.begin(), v.end()); }

Containers Container is an object storing other objects which can be accessed by iterators. Associated types: X::value_type X::iterator X::const_iterator … X Type of a container a Object of type X

Containers Valid expressions a.begin() Beginning of container a a.end() End of container a a.size() Size of container a a.empty() Whether container a is empty

Iterators Iterators are used to point to other objects. Iterators play an interface between data structures and algorithms. container generic algorithm sort vector iterator

Iterators Input Iterator Output Iterator Forward Iterator Get elements out from container Output Iterator Put elements into container Forward Iterator Get persistent elements from container Bidirectional Iterator Be able to get elements in a reversed order Random Access Iterator Arbitrarily access elements

Algorithms After defining iterators, they can be use to specify algorithms. #include <vector> #include <algorithm> int main(){ std::vector<int> v; v.push_back(2); v.push_back(8); v.push_back(5); v.push_back(3); vector<int>::iterator result = find(v.begin(), v.end(), 5); assert(result == v.end() || *result == 5); }

Summary STL contains important components: containers (data structures), iterators, and algorithms. All components are reusable and flexible.

Lab Assignment Create a class called Point with two private data members, a public function Print, and constructors. Use a container store 10 Points, initialize them with non-zero data, and print them. Write a function to find the Point which has the maximum y coordinate by any STL algorithm. The return value is a pair containing the corresponding x and y values.