Quick Overview of STL STL = Standard Template Library Main concept : Container, Iterator Application : Linked list, Stack etc.

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.
Chapter 6 Queues and Deques.
SEG4110 – Advanced Software Design and Reengineering TOPIC J C++ Standard Template Library.
Object Oriented Programming Lect. Dr. Daniel POP Universitatea de Vest din Timişoara Facultatea de Matematică şi Informatică.
. STL: C++ Standard Library (continued). STL Iterators u Iterators are allow to traverse sequences u Methods  operator*  operator->  operator++, and.
Templates and the STL Bryce Boe 2012/09/10 CS32, Summer 2012 B.
. 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.
1 Queues CPS212 Gordon College. 2 Introduction to Queues A queue is a waiting line – seen in daily life –Real world examples – toll booths, bank, food.
Main Index Contents 11 Main Index Contents Container Types Container Types Sequence Containers Sequence Containers Associative Containers Associative Containers.
Main Index Contents 11 Main Index Contents Container Types Container Types Sequence Containers Sequence Containers Associative Containers Associative Containers.
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.
Lecture 11 Standard Template Library Stacks, Queue, and Deque Lists Iterators Sets Maps.
CHP - 9 File Structures. INTRODUCTION In some of the previous chapters, we have discussed representations of and operations on data structures. These.
CSIS 123A Lecture 12 Templates. Introduction  C++ templates  Allow very ‘general’ definitions for functions and classes  Type names are ‘parameters’
Spring 2010 Advanced Programming Section 1-STL Computer Engineering Department Faculty of Engineering Cairo University Advanced Programming Spring 2010.
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
Chapter 16: Searching, Sorting, and the vector Type.
SNU OOPSLA Lab. Chap17. Standard Containers © copyright 2001 SNU OOPSLA Lab.
C++ How to Program, 8/e © by Pearson Education, Inc. All Rights Reserved.
PRESENTED BY: RAJKRISHNADEEPAK.VUYYURU SWAMYCHANDAN.DONDAPATI VINESHKUMARREDDY.LANKA RAJSEKHARTIRUMALA KANDURI ALAN.
Main Index Contents 11 Main Index Contents Week 3 – The Vector Container.
111 © 2002, Cisco Systems, Inc. All rights reserved.
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)
C++ STL CSCI 3110.
Data structures Abstract data types Java classes for Data structures and ADTs.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 22: Standard Template Library (STL)
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,
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.
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.
Lists Chapter 8. 2 Linked Lists As an ADT, a list is –finite sequence (possibly empty) of elements Operations commonly include: ConstructionAllocate &
CE Operating Systems Lecture 17 File systems – interface and implementation.
Collections Data structures in Java. OBJECTIVE “ WHEN TO USE WHICH DATA STRUCTURE ” D e b u g.
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.
Intro to the C++ STL Timmie Smith September 6, 2001.
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.
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.
CSCI-383 Object-Oriented Programming & Design Lecture 30.
CSCI  Sequence Containers – store sequences of values ◦ vector ◦ deque ◦ list  Associative Containers – use “keys” to access data rather than.
Chapter 16: Searching, Sorting, and the vector Type.
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.
Standard Template Library
Understanding Algorithms and Data Structures
CHP - 9 File Structures.
Programming with ANSI C ++
Standard Template Library
Standard Template Library (STL)
ENERGY 211 / CME 211 Lecture 19 November 3, 2008.
C++ Programming Standard Library
Prof. Michael Neary Lecture 7: The STL Prof. Michael Neary
Final Exam Review COP4530.
Standard Template Library Model
Data structures and algorithms
Lecture 8 : Intro. to STL (Standard Template Library)
Tenth step for Learning C++ Programming
Standard Template Library
Standard Template Library
Presentation transcript:

Quick Overview of STL STL = Standard Template Library Main concept : Container, Iterator Application : Linked list, Stack etc.

Container Types VectorRandom access to elements, efficient insertion at end vector Specialization of vector optimized for bool listEfficient insertion and removal throughout dequeRandom access, efficient insertion at front or back set Elements maintained in order, efficient test for inclusion, insertion, and removal multisetSet with repeated copies bitset Bit container templated on size rather than contained type map Access to values via keys, efficient insertion and removal multimapMap permitting duplicate keys stringCharacter container enhanced for string operations

Container Adaptors stackInsertions and removals only from top queueInsertions at back, removals from front priority queueEfficient access and removal of largest values

Selecting Container 1. How are values going to be accessed? If random access is important, then a vector or a deque should be used. If sequential access is sufficient, then one of the other structures may be suitable. 2. Is the order in which values are maintained in the collection important? There are a number of different ways values can be sequenced. If a strict ordering is important throughout the life of the container, then the set data structure is an obvious choice, as insertions into a set are automatically placed in order. If this ordering is important only at one point—for example, at the end of a long series of insertions—then it might be easier to place the values into a list or vector, and sort the resulting structure at the appropriate time. If the order that values are held in the structure is related to the order of insertion, then a stack, queue, or list may be the best choice. 3. Will the size of the structure vary widely over the course of execution? If so, a list or set might be the best choice. A vector or deque will continue to maintain a large buffer even after elements have been removed from the collection. Conversely, if the size of the collection remains relatively fixed, than a vector or deque will use less memory than a list or set holding the same number of elements. 4. Is it possible to estimate the size of the collection? The vector data structure provides a way to pre-allocate a block of memory of a given size, using the reserve() member function. This ability is not provided by the other containers.

Selecting Container (continues) 5. Is testing to see whether a value is contained in the collection a frequent operation? If so, then the set or map containers would be a good choice. Testing to see whether a value is contained in a set or map can be performed in a very small number of steps, logarithmic in the size of the container, whereas testing to see if a value is contained in one of the other types of collections might require comparing the value against every element being stored by the container. 6. Is the collection indexed? That is, can the collection be viewed as a series of key/value pairs? If the keys are integers between 0 and some upper limit, a vector or deque should be used. On the other hand, if the key values are some other ordered datatype—character, string, or user-defined type—the map container can be used. 7. Can values be related to each other? All values stored in any container provided by the Standard C++ Library must be able to test for equality against another similar value, but not all need to recognize the relational less-than operator. However, if values cannot be ordered using the relational less-than operator, they cannot be stored in a set or a map.

Selecting Container (continues) 8. Is finding and removing the largest value from the collection a frequent operation? If the answer is yes, the priority queue is the best data structure to use. 9. At what positions are values inserted into or removed from the structure? If values are inserted into or removed from the middle, then a list is the best choice. If values are inserted only at the beginning, a deque or a list is the preferred choice. If values are inserted or removed only at the end, a stack or queue may be a logical choice. 10. Is the merging of two or more sequences into one a frequent operation? If so, a set or a list would seem to be the best choice, depending whether the collection is maintained in order. Merging two sets is a very efficient operation. If the collections are not ordered, but the efficient splice() member function from class list can be used, then the list datatype is to be preferred, since this operation is not provided in the other containers.