CSCI 383 Object-Oriented Programming & Design Lecture 25 Martin van Bommel.

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

Stacks, Queues, and Linked Lists
C++ Sets and Multisets Set containers automatically sort their elements automatically. Multisets allow duplication of elements whereas sets do not. Usually,
Templates and the STL Bryce Boe 2012/09/10 CS32, Summer 2012 B.
The Standard Template Library – part 2. auto_ptr Regular pointers may cause memory leaks Regular pointers may cause memory leaks void f() { SomeClass.
Week 5 - Associative Containers: sets and maps. 2 2 Main Index Main Index Content s Content s Container Types Sequence Containers Adapter Containers Associative.
1 L43 Collections (3). 2 OBJECTIVES  To use the collections framework interfaces to program with collections polymorphically.  To use iterators to “walk.
Main Index Contents 11 Main Index Contents Model for a Queue Model for a Queue The Queue The Queue ADTQueue ADT (3 slides) Queue ADT Radix Sort Radix Sort.
Main Index Contents 11 Main Index Contents Container Types Container Types Sequence Containers Sequence Containers Associative Containers Associative Containers.
Chapter 12 C Data Structures Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
Quick Overview of STL STL = Standard Template Library Main concept : Container, Iterator Application : Linked list, Stack etc.
Maps A map is an object that maps keys to values Each key can map to at most one value, and a map cannot contain duplicate keys KeyValue Map Examples Dictionaries:
Lecture 11 Standard Template Library Stacks, Queue, and Deque Lists Iterators Sets Maps.
Data Structures: CSCI 362 – Stack Implementation Data Structures: CSCI 362 – Stack Implementation lecture notes adapted from Data Structures with C++ using.
Data Structures Using C++ 2E
Java™ How to Program, 9/e Presented by: Dr. José M. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
Containers Overview and Class Vector
CNS  Sequences  vector,deque,list,(string),forward_list  Container Adapters  queue, stack, priority_queue  Associative Containers  set, unordered_set.
SNU OOPSLA Lab. Chap17. Standard Containers © copyright 2001 SNU OOPSLA Lab.
C++ How to Program, 8/e © by Pearson Education, Inc. All Rights Reserved.
Main Index Contents 11 Main Index Contents Week 3 – The Vector Container.
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)
Review for Final Andy Wang Data Structures, Algorithms, and Generic Programming.
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.
STL multimap Container. STL multimaps multimaps are associative containers –Link a key to a value –AKA: Hashtables, Associative Arrays –A multimap allows.
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.
Friends & Standard Template Library CSCI3110 Advanced Data Structures Lecturer: Dr. Carroll and Nan Chen.
1 Finding Shortest Paths with A* Search A* search operates similarly to Dijkstra’s algorithm, but extends the cost function to include an estimated distance.
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 &
Chapter 22 STL Containers §22.1 STL Basics §22.2 STL Iterators §22.3 Sequence Containers §22.4 Associative Containers §22.5 Container Adapters.
CS212: Object Oriented Analysis and Design Lecture 24: Introduction to STL.
The ADT Table The ADT table, or dictionary Uses a search key to identify its items Its items are records that contain several pieces of data 2 Figure.
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.
STL – Standard Template Library L. Grewe. 2 Goals Lots of important algorithms, data structures in CS using Templates. is a software library partially.
1 Associative Containers Ordered Ordered Unordered UnorderedSets Maps as sets of pairs Set API Ex: Sieve of Eratosthenes Ex: Sieve of EratosthenesImplementation.
The Standard Template Library Container Classes Version 1.0.
Copyright © 2009 – Curt Hill Standard Template Library An Introduction.
C++ Review STL CONTAINERS.
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.
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.
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.
Templates 3 Templates and type parameters The basic idea templates is simple: we can make code depend on parameters, so that it can be used in different.
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
Set Collection A Bag is a general collection class that implements the Collection interface. A Set is a collection that resembles a Bag with the provision.
Sorted Linked List Same objective as a linked list, but it should be sorted Sorting can be custom according to the type of nodes Offers speedups over non-sorted.
Standard Template Library (STL)
Basic Data Structures.
Array Array is a variable which holds multiple values (elements) of similar data types. All the values are having their own index with an array. Index.
Prof. Michael Neary Lecture 7: The STL Prof. Michael Neary
Associative Structures
Final Exam Review COP4530.
Recitation Outline C++ STL associative containers Examples
Tenth step for Learning C++ Programming
Standard Template Library
Standard Template Library
Presentation transcript:

CSCI 383 Object-Oriented Programming & Design Lecture 25 Martin van Bommel

Associative Containers Provide direct access to store and retrieve elements via keys (often called search keys) Each associate container maintains its keys in sorted order Implemented as a (self-balancing) Binary Search Tree (BST) Time complexity of Find, Insert, Delete ? The ordering of the elements is determined by a comparator function object Default is less If f is an object of class less and x and y are objects of class T, then f(x,y) returns true if x < y and false otherwise If T is a user-defined type (e.g., Student ), must provide overloading of operator<

Associative Containers The four associative containers are set, multiset map, multimap Iterating through an associative container traverses it in the sort order for that container

Set & Multiset Simple associative containers, meaning that elements are their own keys (i.e., a key is not associated with any additional value) Maintain keys in sorted order Provide set operations Union Intersection Difference Symmetric difference Handout #15

Map & Multimap Pair associate containers, meaning that its value type is a pair (often called key/value pair) Duplicate keys are allowed in a multimap, so multiple values can be associated with a single key (i.e., a one-to-many relationship) Duplicate keys are not allowed in a map, a single value can be associated with each key (i.e., a one-to-one mapping) Also known as an associative array, providing key in map ’s subscript operator[] locates value associated with key Handout #15

Container Adaptors They are not containers, but adapt other containers Do not provide the actual data structure implementation in which elements can be stored Provide restricted subset of container functionality Do not support iterators A benefit of an adaptor class is that you can choose an appropriate underlying data structure A stack is implemented with a deque by default but this can be changed with a second argument in constructor, e.g., vector instead of deque

Adaptor Containers The STL provides three adaptor containers stack queue priority_queue All three adaptor classes provide member functions push, pop and top that properly insert an element, remove an element, and check the “top” element (some implementations of queue use front to get a reference to the “first” element) Handout #16

bitset A special container designed to store bits (i.e., elements with only two possible values: 0 or 1, true or false,...) Very useful for representing a set of bit flags Very similar to a regular array, but optimizing for space allocation Each element occupies only one bit, which is eight times less than the smallest elemental type in C++ (i.e., char ) bitset s are fixed in size at compile time (i.e., unlike vector which allows for dynamic resizing)

Sieve of Eratosthenes A simple and ancient algorithm for finding all prime numbers up to a specified integer Created by Eratosthenes, an ancient Greek mathematician ALGORITHM (Done in class)