STL List.

Slides:



Advertisements
Similar presentations
Linked Lists.
Advertisements

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.
Lists and the Collection Interface Chapter 4. Chapter Objectives To become familiar with the List interface To understand how to write an array-based.
Data Structures Using C++ 2E
Data Structures: A Pseudocode Approach with C
More on the STL vector list stack queue priority_queue.
Lists and the Collection Interface Chapter 4. Chapter 4: Lists and the Collection Interface2 Chapter Objectives To become familiar with the List interface.
Fall 2007CS 2251 Lists and the Collection Interface Chapter 4.
C++ Programming: Program Design Including Data Structures, Second Edition Chapter 22: Standard Template Library (STL)
Basic C++ Sequential Container Features
Writing Your Own STL Container Ray Lischner
Data Structures Using C++ 2E
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.
Standard Template Library The Standard Template Library was recently added to standard C++. –The STL contains generic template classes. –The STL permits.
Lists Chapter 8. 2 Linked Lists As an ADT, a list is –finite sequence (possibly empty) of elements Operations commonly include: ConstructionAllocate &
Lecture 7 : Intro. to STL (Standard Template Library)
List Interface and Linked List Mrs. Furman March 25, 2010.
Chapter 5 Linked List by Before you learn Linked List 3 rd level of Data Structures Intermediate Level of Understanding for C++ Please.
Chapter 17: Linked Lists. Objectives In this chapter, you will: – Learn about linked lists – Learn the basic properties of linked lists – Explore insertion.
Glenn Stevenson CSIS 113A MSJC CSIS 123A Lecture 3 Vectors.
Programming in C++ Michal Brabec Petr Malý. Standard Template Library Containers - vector, map, set, deque, list Algorithms - copy, replace, sort, find.
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.
Lists and the Collection Interface Chapter 4. Chapter 4: Lists and the Collection Interface2 Chapter Objectives To become familiar with the List interface.
Linked Lists Source: presentation based on notes written by R.Kay, A. Hill and C.Noble ● Lists in general ● Lists indexed using pointer arrays ● Singly.
Object-Oriented Programming (OOP) Lecture No. 41
Motivation for Generic Programming in C++
Standard Template Library
Module 20/21/22: The Standard Template Library
CS212: Object Oriented Analysis and Design
Chapter 16: Linked Lists.
C++ Programming:. Program Design Including
Iterators and Sequences
Data Structure By Amee Trivedi.
Copy Constructor / Destructors Stacks and Queues
Programming with ANSI C ++
Standard Template Library
CSCI-255 LinkedList.
Linked Lists Chapter 6 Section 6.4 – 6.6
Fundamentals of Java: AP Computer Science Essentials, 4th Edition
Standard Template Library (STL)
Chapter 4 Linked Lists.
STL Common tools for C++.
Collections Intro What is the STL? Templates, collections, & iterators
Prof. Michael Neary Lecture 7: The STL Prof. Michael Neary
Introduction to Linked Lists
Chapter 22: Standard Template Library (STL)
Array Lists Chapter 6 Section 6.1 to 6.3
Abstract Data Types Iterators Vector ADT Sections 3.1, 3.2, 3.3, 3.4
Linked Lists.
Object Oriented Programming COP3330 / CGS5409
Linked List Intro CSCE 121 J. Michael Moore.
Chapter 3 Lists, Stacks, and Queues Abstract Data Types, Vectors
priority_queue<T>
[Chapter 4; Chapter 6, pp ] CSC 143 Linked Lists [Chapter 4; Chapter 6, pp ]
Programming II (CS300) Chapter 07: Linked Lists and Iterators
Standard Template Library Model
Chapter 17: Linked Lists.
The Standard Template Library
Lists - I The List ADT.
Lists - I The List ADT.
Lecture 8 : Intro. to STL (Standard Template Library)
Lecture 16 Section 6.2 Thu, Mar 1, 2007
Data Structures & Algorithms
Collections Intro What is the STL? Templates, collections, & iterators
Chapter 3 Lists, Stacks, and Queues
The List Container and Iterators
STL List.
Presentation transcript:

STL List

Sequence Containers Sequence (indexed) container: Store elements in defined order (0, 1, 2…) Three predefined sequence containers: vector deque list

List std::list Manages a linked list Doubly linked – allows for backward navigation

List Container class proving dynamic array #include <list> Declaration includes type: list<int> intList; list<string> stringList;

Constructors Construction options: () : empty (size) : filled with size copies of 0 or default constructor (size, value) : filled with size copies of value {list} list<int> v; //empty list<int> v2(10); //10 default ints list<int> v3(10, 99); //10 copies of 99 list<int> v4 {1, 2, 3}; //3 defined elements

Fundamental Ops Add item to end: list.push_back(T) OR list.push_front(T) Get size list.size()

No Random Access!!! No .at(i) or [i]

Iterators Iterator Pointer like object Know how to traverse collection Standard way to access elements of any collection

Iterators List.begin() is iterator at first item List.end() is one step past end

Iterator Movement ++ and – to advance

Iterator Access Use dereference operator to access: And assign:

Iterator Access Use -> to access members of what iterator points to:

Iterator Based Loop Start at begining

Iterator Based Loop Go up to end

Iterator Based Loop Step by one position

Iterator Based Loop Print the current item

Copies Assignment does deep copy of contents

Pass By Ref Pass by ref to avoid copy:

Comparison std::list Linked List std::vector Array List

Comparison List: Pro Faster at front and back Can have advantage with large elements Can splice easily

Comparison Vector: Pro Random access is fast Array generally performs better than pointers for similar tasks

Comparison Small items at end https://baptiste-wicht.com/posts/2012/12/cpp-benchmark-vector-list-deque.html

Comparison Linear Search https://baptiste-wicht.com/posts/2012/12/cpp-benchmark-vector-list-deque.html

Comparison Small items at front https://baptiste-wicht.com/posts/2012/12/cpp-benchmark-vector-list-deque.html

Comparison Remove a large item from middle https://baptiste-wicht.com/posts/2012/12/cpp-benchmark-vector-list-deque.html