CS212: Object Oriented Analysis and Design Lecture 26: STL Containers.

Slides:



Advertisements
Similar presentations
. STL: C++ Standard Library (continued). STL Iterators u Iterators are allow to traverse sequences u Methods  operator*  operator->  operator++, and.
Advertisements

Multimaps. Resources -- web For each new class, browse its methods These sites are richly linked, and contain indexes, examples, documents and other resources.
C++ Templates. What is a template? Templates are type-generic versions of functions and/or classes Template functions and template classes can be used.
Data Structures: A Pseudocode Approach with C
C++ Sets and Multisets Set containers automatically sort their elements automatically. Multisets allow duplication of elements whereas sets do not. Usually,
Week 5 - Associative Containers: sets and maps. 2 2 Main Index Main Index Content s Content s Container Types Sequence Containers Adapter Containers Associative.
COMP 171 Data Structures and Algorithms Tutorial 1 Template and STL.
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 17 Linked.
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.
Basic C++ Sequential Container Features
Lecture 11 Standard Template Library Stacks, Queue, and Deque Lists Iterators Sets Maps.
Templates and the STL.
Writing Your Own STL Container Ray Lischner
Spring 2010 Advanced Programming Section 1-STL Computer Engineering Department Faculty of Engineering Cairo University Advanced Programming Spring 2010.
Chapter 19 - basic definitions - order statistics ( findkth( ) ) - balanced binary search trees - Java implementations Binary Search Trees 1CSCI 3333 Data.
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
DATA STRUCTURES AND ALGORITHMS Lecture Notes 12 Prepared by İnanç TAHRALI.
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)
C++ STL CSCI 3110.
STL multimap Container. STL multimaps multimaps are associative containers –Link a key to a value –AKA: Hashtables, Associative Arrays –A multimap allows.
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.
Prof. Amr Goneid, AUC1 CSCI 210 Data Structures and Algorithms Prof. Amr Goneid AUC Part 5. Dictionaries(2): Hash Tables.
Standard Template Library The Standard Template Library was recently added to standard C++. –The STL contains generic template classes. –The STL permits.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Copyright © 2012 Pearson Education, Inc. Chapter 17: Linked Lists.
CS212: Object Oriented Analysis and Design Lecture 24: Introduction to STL.
Lecture 11 Standard Template Library Lists Iterators Sets Maps.
Elementary Data Organization. Outline  Data, Entity and Information  Primitive data types  Non primitive data Types  Data structure  Definition 
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.
Data Structures for Midterm 2. C++ Data Structure Runtimes.
A gentle introduction to the standard template library (STL) Some references:
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.
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.
C++ Review STL CONTAINERS.
1 Chapter 3 Lists, Stacks, and Queues Reading: Sections 3.1, 3.2, 3.3, 3.4 Abstract Data Types (ADT) Iterators Implementation of Vector.
CSCI 383 Object-Oriented Programming & Design Lecture 25 Martin van Bommel.
Chapter 17 – Templates. Function Templates u Express general form for a function u Example: template for adding two numbers Lesson 17.1 template Type.
STL Associative Containers navigating by key. Pair Class aggregates values of two, possibly different, types used in associative containers defined in.
CSCI  Sequence Containers – store sequences of values ◦ vector ◦ deque ◦ list  Associative Containers – use “keys” to access data rather than.
Main Index Contents 11 Main Index Contents Sets Defined by a key along with other data Sets Defined by a key along with other data Key-Value Data Key-Value.
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.
List Structures What is a list? A homogeneous collection of elements with a linear relationship between the elements linear relationship - each element.
Prof. Amr Goneid, AUC1 CSCI 210 Data Structures and Algorithms Prof. Amr Goneid AUC Part 5. Dictionaries(2): Hash Tables.
Data Structures: A Pseudocode Approach with C 1 Chapter 5 Objectives Upon completion you will be able to: Explain the design, use, and operation of a linear.
Object-Oriented Programming (OOP) Lecture No. 41
Standard Template Library
CS212: Object Oriented Analysis and Design
CSCI 210 Data Structures and Algorithms
Standard Template Library (STL)
Object Oriented Programming COP3330 / CGS5409
Associative Structures
Chapter 18: Linked Lists.
CS212: Object Oriented Analysis and Design
Recitation Outline C++ STL associative containers Examples
Doubly Linked List Implementation
Chapter 17: Linked Lists.
Iterators and STL Containers
Lecture 8 : Intro. to STL (Standard Template Library)
Standard Template Library
Some Definitions vector, string, deque, and list are standard sequence containers. set, multiset, map, multimap, unordered_set, unordered_multiset, unordered_map.
Presentation transcript:

CS212: Object Oriented Analysis and Design Lecture 26: STL Containers

Recap of Lecture 25 STL Iterators Iterator hierarchy

Outline of Lecture 26 STL Lists Set Maps

Iterator: Is this really important? Creating your own iterators Using some sophisticated iterators Use the STL algorithms Create your own reusable algorithm templates

STL: Lists Lists are sequence containers Allow constant time insert and erase operations anywhere within the sequence Iteration in both directions. List containers are implemented as doubly-linked lists template > class list;

Drawbacks Direct access to the elements by their position is missing It does not have an operator[ ] Takes linear time in the distance between a known location and target location Consume some extra memory to keep the linking information associated to each element

Container properties Sequence Elements in sequence containers are ordered in a strict linear sequence. Individual elements are accessed by their position in this sequence. Doubly-linked list Allowing constant time insert and erase operations before or after a specific element (even of entire ranges), But no direct random access. Allocator-aware The container uses an allocator object to dynamically handle its storage needs.

List Constructors explicit list(const Allocator &a = Allocator( ) ); explicit list(size_type num, const T &val = T ( ), const Allocator &a = Allocator( )); list(const list &ob); template list(InIter start, InIter end, const Allocator &a = Allocator( )); Constructs an empty list Constructs a list that has num elements with the value val Constructs a list that contains the same elements as ob Constructs a list contains the elements in the range specified by the iterators start and end

Common operations on list Create a list Insert an element: push_front() and push_back() Sort Robustness … Performance comparison

Map Supports an associative container Unique keys are mapped with values Once a value has been stored, can be retrieved by using key The power of a map is that you can look up a value given its key A map can hold only unique keys. Duplicate keys are not allowed.

Map constructors explicit map (const Comp &cmpfn = Comp( ), const Allocator &a = Allocator( ) ); map (const map &ob); template map (InIter start, InIter end, const Comp &cmpfn = Comp( ), const Allocator &a = Allocator( )); Constructs an empty map Constructs a map that contains the same elements as ob Constructs a map that contains the elements in the range specified by the iterators start and end

Set A container that accept only one of each thing placed in it It also sorts the elements Sorting isn’t intrinsic to the conceptual definition of a set But the STL set stores its elements in a balanced binary tree to provide rapid lookups, Thus producing sorted results when traversed

Thank you Next Lecture: Algorithms