C++ Review STL CONTAINERS.

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

SEG4110 – Advanced Software Design and Reengineering TOPIC J C++ Standard Template Library.
C++ Templates. What is a template? Templates are type-generic versions of functions and/or classes Template functions and template classes can be used.
Templates and the STL Bryce Boe 2012/09/10 CS32, Summer 2012 B.
More on the STL vector list stack queue priority_queue.
C++ Programming: Program Design Including Data Structures, Second Edition Chapter 22: Standard Template Library (STL)
Standard Template Library. Homework List HW will be posted on webpage Due Nov 15.
Standard Template Library (STL) Overview – Part 1 Yngvi Bjornsson.
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.
1 Stack Data : a collection of homogeneous elements arranged in a sequence. Only the first element may be accessed Main Operations: Push : insert an element.
Chapter 24 Dispensers and dictionaries. This chapter discusses n Dictionaries n Dispensers u stacks u queues u priority queues.
Templates and the STL.
Writing Your Own STL Container Ray Lischner
CSIS 123A Lecture 12 Templates. Introduction  C++ templates  Allow very ‘general’ definitions for functions and classes  Type names are ‘parameters’
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
1 Hash Tables  a hash table is an array of size Tsize  has index positions 0.. Tsize-1  two types of hash tables  open hash table  array element type.
DATA STRUCTURES ACM EXECUTIVE BODY 2k11.  A series of elements of same type  Placed in contiguous memory locations  Can be individually referenced.
Data Structures Using C++ 2E
Chapter 3 List Stacks and Queues. Data Structures Data structure is a representation of data and the operations allowed on that data. Data structure is.
Containers Overview and Class Vector
CNS  Sequences  vector,deque,list,(string),forward_list  Container Adapters  queue, stack, priority_queue  Associative Containers  set, unordered_set.
Jan 12, 2012 Introduction to Collections. 2 Collections A collection is a structured group of objects Java 1.2 introduced the Collections Framework Collections.
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.
CSS446 Spring 2014 Nan Wang  Java Collection Framework ◦ LinkedList ◦ Set ◦ Map 2.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 22: 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:
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.
Chapter 22 STL Containers §22.1 STL Basics §22.2 STL Iterators §22.3 Sequence Containers §22.4 Associative Containers §22.5 Container Adapters.
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.
The Standard Template Library Container Classes Version 1.0.
CH 6 : VECTORS, LISTS AND SEQUENCES ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH,
CSCI 383 Object-Oriented Programming & Design Lecture 25 Martin van Bommel.
Collection types CS Chakrabarti Motivation  Thus far the only collection types we have used are vector and matrix  Problem #1: given an input.
Chapter 17 – Templates. Function Templates u Express general form for a function u Example: template for adding two numbers Lesson 17.1 template 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.
Collections ABCD ABCD Head Node Tail Node array doubly linked list Traditional Arrays and linked list: Below is memory representation of traditional.
Final Exam Review COP4530.
Object-Oriented Programming (OOP) Lecture No. 41
Cpt S 122 – Data Structures Abstract Data Types
Regarding homework 9 Many low grades
Standard Template Library (STL)
ENERGY 211 / CME 211 Lecture 19 November 3, 2008.
What remains Topics Assignments Final exam
Prof. Michael Neary Lecture 7: The STL Prof. Michael Neary
structures and their relationships." - Linus Torvalds
Abstract Data Types (ADTs)
Final Exam Review COP4530.
priority_queue<T>
Recitation Outline C++ STL associative containers Examples
Iterators and STL Containers
Tenth step for Learning C++ Programming
Some Definitions vector, string, deque, and list are standard sequence containers. set, multiset, map, multimap, unordered_set, unordered_multiset, unordered_map.
structures and their relationships." - Linus Torvalds
Standard Template Library
Presentation transcript:

C++ Review STL CONTAINERS

STANDARD TEMPLATE LIBRARY - REVISION Containers are ADTs to store collection of related data. Example: vector, list, map Member functions to store, add, delete, update, access and related operations. Example: push_back, at Iterators are objects to iterate over the elements in the containers and access them. Algorithms are set of well known commonly used algorithms working with iterators. Example: sort, swap vector sort container generic algorithm iterator

BASIC CONTAINERS Maintains the order of the inserted elements as specified. Examples: Vector: Growable array (doubling strategy) with flexible length. Allows random access and contiguous allocation of memory. List: Doubly linked list. Bidirectional access with fast insert and delete. No random access. Deque: Double ended queue. Fast insert and delete at the ends of the queue. Allows random access and flexible length. No contiguous allocation of memory.

ADAPTIVE CONTAINERS Adapted version of other containers with restricted operations for simplicity. Examples: Stack: Last In First Out (LIFO). push(), pop(), top(), size(), empty() Queue: First In First Out (FIFO). push(), pop(), front(), back(), size(), empty() Priority_queue: Like queue but element with highest priority is first in the queue. push(), pop(), top(), size(), empty()

ASSOCIATIVE CONTAINERS Elements are inserted according to a predefined order. Maps: Dictionary with (key,value) pair. Key states the order of the sequence. Sets: Container with sorted elements. Can be viewed as a map where value and key are same element. 1 2 3 Hello Hi Howdy 1, 2,3,5,7,8

Distinct Vs. Non-Distinct Non-multi: Cannot handle non-unique keys or elements Map: Keys should be unique Set: Elements should be unique Multiple: Can handle multiple keys or elements Multimap: Multiple non-unique keys Multiset: Duplicate elements allowed. Eg: S = {1,2,3,4,5} is a set but S1= {1,2,2,4,5} is a multiset.

ORDERED VS UNORDERED Ordered: Order preserved in storing Faster range iteration than unordered counterparts but slower element access. Map Multimap Set Multiset Unordered: No order in storing. Uses hashing. Faster access of elements. Range iteration is slower than ordered counterpart. Unordered_map Unordered_multimap Unordered_set

Exercise Design a barcode scanner for a super market: Given the barcodes of the items in your shopping list, look up in the inventory database for its availability and if available print the quantity. What will be the underlying container? Read the inventory data (item barcode, quantity, per item cost) from the file given in the web. Bonus: Prepare the receipt (total cost) for the shopping list.