ENERGY 211 / CME 211 Lecture 19 November 3, 2008.

Slides:



Advertisements
Similar presentations
1 Linked lists Sections 3.2, 3.3, 3.5 Chapter 3 Lists, Stacks, and Queues Abstract Data Types, Vectors.
Advertisements

Hold data and provide access to it. Random-access containers: -Allow accessing any element by index -arrays, vectors Sequential containers: -Allow accessing.
Main Index Contents 11 Main Index Contents Shifting blocks of elements… Shifting blocks of elements… Model of a list object… Model of a list object… Sample.
SEG4110 – Advanced Software Design and Reengineering TOPIC J C++ Standard Template Library.
Data Structures Using C++ 2E
Main Index Contents 11 Main Index Contents Container Types Container Types Sequence Containers Sequence Containers Associative Containers Associative Containers.
C++ Programming: Program Design Including Data Structures, Second Edition Chapter 22: Standard Template Library (STL)
Standard Template Library (STL) Overview – Part 1 Yngvi Bjornsson.
Basic C++ Sequential Container Features
Liang, Introduction to Java Programming, Tenth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 20 Lists, Stacks, Queues, and Priority.
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.
Lecture 11 Standard Template Library Stacks, Queue, and Deque Lists Iterators Sets Maps.
Main Index Contents 11 Main Index Contents Week 4 – Stacks.
Data Structures Using C++ 2E
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Custom Templatized Data Structures.
CNS  Sequences  vector,deque,list,(string),forward_list  Container Adapters  queue, stack, priority_queue  Associative Containers  set, unordered_set.
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)
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.
HIT2037- HIT6037 Software Development in Java 22 – Data Structures and Introduction.
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,
COP INTERMEDIATE JAVA Data Structures. A data structure is a way of organizing a collection of data so that it can be manipulated effectively. A.
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.
 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.
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.
Week 2 - Friday.  What did we talk about last time?  Computing Big Oh.
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.
Glenn Stevenson CSIS 113A MSJC CSIS 123A Lecture 3 Vectors.
Lecture 7.  There are 2 types of libraries used by standard C++ The C standard library (math.h) and C++ The C++ standard template library  Allows us.
Chapter 17 – Templates. Function Templates u Express general form for a function u Example: template for adding two numbers Lesson 17.1 template Type.
CSCI  Sequence Containers – store sequences of values ◦ vector ◦ deque ◦ list  Associative Containers – use “keys” to access data rather than.
Standard Template Library a collection of useful tools.
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.
1 Data Organization Example 1: A simple text editor –Store the text buffer as a list of lines. –How would we implement the UNDO operation? Example 2: Parsing.
Object-Oriented Programming (OOP) Lecture No. 41
Lecture 35a OOP The STL Standard Template Library
Standard Template Library
CS212: Object Oriented Analysis and Design
C++ Programming:. Program Design Including
Data Structure By Amee Trivedi.
Copy Constructor / Destructors Stacks and Queues
Standard Template Library
The List ADT Sections 3.2, 3.3, 3.5 Introduction
Chapter 20 Lists, Stacks, Queues, and Priority Queues
Standard Template Library (STL)
ENERGY 211 / CME 211 Lecture 12 October 17, 2008.
Prof. Michael Neary Lecture 7: The STL Prof. Michael Neary
Basic Data Structures.
Chapter 20 Lists, Stacks, Queues, and Priority Queues
CSC 143 Stacks [Chapter 6].
Copyright © – Curt Hill STL List Details Copyright © – Curt Hill.
Lecture 8 : Intro. to STL (Standard Template Library)
Standard Template Library
STL List.
ENERGY 211 / CME 211 Lecture 30 December 5, 2008.
ENERGY 211 / CME 211 Lecture 18 October 31, 2008.
Standard Template Library
Chapter 20 Lists, Stacks, Queues, and Priority Queues
The List Container and Iterators
STL List.
A dictionary lookup mechanism
Standard Template Library
Presentation transcript:

ENERGY 211 / CME 211 Lecture 19 November 3, 2008

Containers Standard C++ Library provides classes that implement containers of objects Can store any object that can be copied Types of containers: Sequence containers, for ordered collections of elements Associative containers, for unordered collections elements identified by other means examples: sets and maps

Sequence Containers vector<T> stores elements of type T elements stored contiguously in memory elements can be relocated if vector grows, reducing efficiency deque<T> is a double-ended queue fast addition at both ends; middle slower doesn't relocate elements access slightly slower than vector list<T> is a doubly-linked list element access slower, no random access insertion/deletion always fast

Iterator Member Functions Used to iterate over all elements within a container begin() points to first element end() points to location beyond last element, to know when to end iteration rbegin() points to last element, for reverse iteration rend() points to location before first element, for concluding reverse iteration

Iterator Types For defining your own iterators Iterator type names preceded by container type and :: Types: iterator for forward iteration, reverse_iterator for backward For const containers, precede iterator type name with const_ Can initialize iterators from container member functions like begin() Then, can use ++, *, etc. on iterator

Modifying Containers push_back(t) adds t to end, push_front(t) to beginning (not for vectors) insert(iter,t) adds t before position pointed to by iter erase(iter) removes element at iter Can also use ranges of iterators with insert and erase To remove all elements: clear()

Sizing Containers Can declare sequential containers with an unsigned int initializer to pre-allocate that number of elements Can use resize(unsigned int) member function to change size later In both cases, can add argument of value type to initialize pre-allocated elements Always pre-allocate if possible, for efficiency

More string Operations Strings are containers too Additional string-specific overloads of insert and erase available Use assign to replace a string with another or replace to replace a portion of a string substr extracts a portion of a string Use find, rfind to search within a string, compare to compare strings Many more! See cppreference.com

Stacks and Queues A stack is a sequence in which elements are added/removed in a LIFO (last in/first out) manner A queue uses FIFO (first in/first out) A priority_queue orders elements by a given priority Use push(item) to add element, pop() to remove first element Use top() for first element (for queue, use front(), back() to get first, last)

Next Time All about Associative Containers