Standard Template Library (STL) - Use Vector and Deque

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.
Chapter 6 Queues and Deques.
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.
C++ Templates. What is a template? Templates are type-generic versions of functions and/or classes Template functions and template classes can be used.
Chapter 7: User-Defined Functions II
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 10: Records ( structs )
. STL: C++ Standard Library. Main Ideas u General purpose: generic data structures & algorithms, templates u Flexibility: Allows for many combinations.
. The Standard C++ Library. 2 Main Ideas Purpose Flexibility Efficiency Simple & Uniform Interface.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 17: Linked Lists.
C++ Programming: From Problem Analysis to Program Design, Second Edition Chapter 11: Records (structs)
C++ Programming: From Problem Analysis to Program Design, Second Edition Chapter 13: Inheritance and Composition.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 12: Inheritance and Composition.
C++ Programming: Program Design Including Data Structures, Second Edition Chapter 22: Standard Template Library (STL)
Data Structures Using C++1 Chapter 13 Standard Template Library (STL) II.
C++ for Engineers and Scientists Third Edition
C++ Programming: Program Design Including Data Structures, Fifth Edition Chapter 17: Linked Lists.
C++ Programming: Program Design Including Data Structures, Fifth Edition Chapter 12: Inheritance and Composition.
Chapter 10: Inheritance and Polymorphism
CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++
. STL: C++ Standard Library (continued). STL Iterators u Iterators are allow to traverse sequences u Methods  operator*  operator->  operator++, and.
Rossella Lau Lecture 12, DCO10105, Semester B, DCO10105 Object-Oriented Programming and Design  Lecture 12: An Introduction to the STL  Basic.
Chapter 11: Inheritance and Polymorphism Java Programming: Program Design Including Data Structures Program Design Including Data Structures.
Data Structures Using C++ 2E
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the basic concepts and uses of arrays ❏ To be able to define C.
CSE 332: C++ Algorithms II From Last Time: Search with Generic Iterators Third generalization: separate iterator type parameter We arrive at the find algorithm.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 13: Inheritance and Composition.
Chapter 10: Records (structs)
Chapter 7: Arrays. In this chapter, you will learn about: One-dimensional arrays Array initialization Declaring and processing two-dimensional arrays.
Data Structures Using C++ 2E
Chapter 11 Inheritance and Composition. Chapter Objectives Learn about inheritance Learn about subclasses and superclasses Explore how to override the.
C++ How to Program, 8/e © by Pearson Education, Inc. All Rights Reserved.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 11: Records ( struct s)
Edited from Powerpoint Slides provided by Thomson Learning
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Standard Template Library (STL)
Chapter 13: Inheritance and Composition
Data Structures Using C++ 2E Chapter 13 Standard Template Library (STL) II.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 22: Standard Template Library (STL)
C++ for Engineers and Scientists Second Edition Chapter 11 Arrays.
Data Structures Using Java1 Chapter 2 Inheritance and Exception Handling.
COP 3530 Data Structures & Algorithms Discussion Session 3.
Friends & Standard Template Library CSCI3110 Advanced Data Structures Lecturer: Dr. Carroll and Nan Chen.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 10: Applications of Arrays (Searching and Sorting) and the vector Type.
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.
Intro to the C++ STL Timmie Smith September 6, 2001.
Java Programming: From Problem Analysis to Program Design, 3e Chapter 11 Inheritance and Polymorphism.
STL CSSE 250 Susan Reeder. What is the STL? Standard Template Library Standard C++ Library is an extensible framework which contains components for Language.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 11: Records ( struct s)
Introduction The STL is a complex piece of software engineering that uses some of C++'s most sophisticated features STL provides an incredible amount.
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.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 17: Linked Lists.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 18: Linked Lists.
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++ Programming:. Program Design Including
Chapter 11: Inheritance and Polymorphism
Standard Template Library (STL)
Chapter 8 Arrays Objectives
Chapter 22: Standard Template Library (STL)
CS212: Object Oriented Analysis and Design
Generic Programming Karl Lieberherr 12/1/2018 Generic Programming.
Presentation transcript:

Standard Template Library (STL) - Use Vector and Deque Chapter 4 Standard Template Library (STL) - Use Vector and Deque Data Structures Using C++

Data Structures Using C++ Chapter Objectives Learn about the Standard Template Library (STL) Become familiar with the three basic components of the STL: containers, iterators, and algorithms Explore how vector and deque containers are used to manipulate data in a program Discover the use of iterators Data Structures Using C++

Data Structures Using C++ Components of the STL Containers Iterators Algorithms Data Structures Using C++

Data Structures Using C++ Container Types Sequence containers (sequential containers) Associative containers Container adapters Data Structures Using C++

Data Structures Using C++ Sequence Containers Vector Deque list Data Structures Using C++

Ways to Declare and Initialize a Vector Container Data Structures Using C++

Operations to Access the Elements of a Vector Container Data Structures Using C++

Operations on a Vector Container Data Structures Using C++

Functions to Determine the Size of a Vector Container Data Structures Using C++

Member Functions Common to All Containers Data Structures Using C++

Member Functions Common to All Containers Data Structures Using C++

Member Functions Common to All Sequence Containers Data Structures Using C++

Data Structures Using C++ Use of Vector Syntax: Vector declaration vector <elemenetType> name(size); Array declaration elementType name[size]; #include <vector> Program Example_use_Vector Demo in class - Data Structures Using C++

Passing Vector as parameter Vector can be passed to functions by either reference or value. Class Demo program chapter4 program exercise 2,3 and 4. Homework project is “Sequential Search by using Vector” - described in Exercise 5. Data Structures Using C++

Prototype of function template copy template<class inputIterator, class outputIterator> outputItr copy(inputIterator first1, inputIterator last, outputIterator first2); Data Structures Using C++

Sequence Container: deque Deque: double-ended queue Implemented as dynamic arrays Elements can be inserted at both ends To use deque container in a program include statement: #include <deque> Data Structures Using C++

Ways to Declare a deq Object Data Structures Using C++

Operations that Can Be Performed on a deq Object Data Structures Using C++

Data Structures Using C++ Use of Deque Syntax: deque declaration - deque <elementType> name(size); - Table 4-7 shows various ways to declare a deque object. - #include <deque> Program Example_use_Deque Demo in class - Data Structures Using C++

Data Structures Using C++ Types of Iteration Input Iterators Output Iterators Forward Iterators Bidirectional Iterators Random Access Iterators Data Structures Using C++

Operations on an Input Iterator Data Structures Using C++

Operations on an Output Iterator Data Structures Using C++

Operations on a Forward Iterator Data Structures Using C++

Operations on a Bidirectional Iterator Data Structures Using C++

Operations on a Random Access Iterator Data Structures Using C++

Data Structures Using C++ Iterator Hierarchy Data Structures Using C++

typedefs Common to All Containers Data Structures Using C++

Data Structures Using C++ istream_iterator Used to input data into a program from an input stream General syntax: istream_iterator<Type> isIdentifier(istream&); Data Structures Using C++

Data Structures Using C++ ostream_iterator Contains the definition of an output stream iterator General syntax: ostream_iterator<Type> osIdentifier(ostream&); or ostream_iterator<Type> osIdentifier(ostream&, char* deLimit); Data Structures Using C++

Programming Example: Grade Report (Input) A sample input file follows: 345 Lisa Miller 890238 Y 4 Mathematics MTH345 4 A Physics PHY357 3 B ComputerSci CSC478 3 B History HIS356 3 A . Input A file containing the data in the form shown previously. Assume the name of the input file is ch4_GradeData.txt and is on floppy disk A. Data Structures Using C++

Programming Example: Grade Report (Output) The desired output for each student is of the following form: Student Name: Lisa Miller Student ID: 890238 Number of courses enrolled: 4 Course No Course Name Credits Grade CSC478 ComputerSci 3 B HIS356 History 3 A MTH345 Mathematics 4 A PHY357 Physics 3 B Data Structures Using C++

Programming Example: Grade Report Course Component Set the course information Print the course information Show the credit hours Show the course number Show the grade Data Structures Using C++

UML Diagram of the class courseType Data Structures Using C++

Programming Example: Grade Report Student Component Set the student information Print the student information Calculate the number of credit hours taken Calculate the GPA Calculate the billing amount Because the grade report will print the courses in ascending order, sort the courses according to the course number Data Structures Using C++

UML Diagram of the class studentType and the Inheritance Hierarchy Data Structures Using C++

Programming Example: Grade Report (Main Algorithm) Declare the variables Open the input file If the input file does not exist, exit the program Open the output file Get the tuition rate Load the students’ data Print the grade reports Data Structures Using C++

Data Structures Using C++ Chapter Summary Components of the STL Types of Containers Operations on Containers Sequence Containers Deque Vector Data Structures Using C++

Data Structures Using C++ Chapter Summary Iterators Types of iteration Operations on iterators Programming example Data Structures Using C++