STL - Algorithms.

Slides:



Advertisements
Similar presentations
Intro to Scala Lists. Scala Lists are always immutable. This means that a list in Scala, once created, will remain the same.
Advertisements

Extension Methods, Anonymous Types LINQ Query Keywords, Lambda Expressions Svetlin Nakov Telerik Corporation
C++ Templates. What is a template? Templates are type-generic versions of functions and/or classes Template functions and template classes can be used.
Beginning C++ Through Game Programming, Second Edition
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
C++ Sets and Multisets Set containers automatically sort their elements automatically. Multisets allow duplication of elements whereas sets do not. Usually,
CSE 115 Week 11 March , Announcements March 26 – Exam 7 March 26 – Exam 7 March 28 – Resign Deadline March 28 – Resign Deadline Lab 7 turned.
Week 10 Recap CSE 115 Spring For-each loop When we have a collection and want to do something to all elements of that collection we use the for-each.
Chapter 8 Search and Sort Asserting Java ©Rick Mercer.
C++ Programming: Program Design Including Data Structures, Second Edition Chapter 22: Standard Template Library (STL)
CS 106 Introduction to Computer Science I 10 / 16 / 2006 Instructor: Michael Eckmann.
CSE 332: C++ Algorithms II From Last Time: Search with Generic Iterators Third generalization: separate iterator type parameter We arrive at the find algorithm.
Data Structures Using C++ 2E
Lists in Python.
Handling Lists F. Duveau 16/12/11 Chapter 9.2. Objectives of the session: Tools: Everything will be done with the Python interpreter in the Terminal Learning.
Sorting. Why Sort? Put matching elements together –Uniqueness testing –Deleting duplicates –Frequency Counting –Set operations Prioritize Elements Reconstruct.
11 COS220 Concepts of PLs AUBG, COS dept Lecture 36 OOP The STL Standard Template Library Reference: MS Developer Studio, Visual C++, Lafore, Chap 15 STL,
Comp 245 Data Structures Linked Lists. An Array Based List Usually is statically allocated; may not use memory efficiently Direct access to data; faster.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Arrays.
Examples using Arrays. Summing Squares Problem: To compute the sum of the squares of N numbers N is given N values are also given These should be read.
Java Script: Arrays (Chapter 11 in [2]). 2 Outline Introduction Introduction Arrays Arrays Declaring and Allocating Arrays Declaring and Allocating Arrays.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 22: Standard Template Library (STL)
Data Collections: Lists CSC 161: The Art of Programming Prof. Henry Kautz 11/2/2009.
Chapter 8 Search and Sort ©Rick Mercer. Outline Understand how binary search finds elements more quickly than sequential search Sort array elements Implement.
CSCI 3327 Visual Basic Chapter 8: Introduction to LINQ and Collections UTPA – Fall 2011.
1 CS 163 Data Structures Chapter 5 Sorting Herbert G. Mayer, PSU Status 5/23/2015.
Introduction The STL is a complex piece of software engineering that uses some of C++'s most sophisticated features STL provides an incredible amount.
Language Find the latest version of this document at
14-1 Computing Fundamentals with C++ Object-Oriented Programming and Design, 2nd Edition Rick Mercer Franklin, Beedle & Associates, 1999 ISBN
Chapter  Array-like data structures  ArrayList  Queue  Stack  Hashtable  SortedList  Offer programming convenience for specific access.
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.
7 - Programming 7J, K, L, M, N, O – Handling Data.
Lecture 36 OOP The STL Standard Template Library
Motivation for Generic Programming in C++
Standard Template Library
Module 20/21/22: The Standard Template Library
Chapter 9: Sorting and Searching Arrays
Computer Organization and Design Pointers, Arrays and Strings in C
Introduction to LINQ and Generic Collections
Python: Control Structures
Recitation 13 Searching and Sorting.
Sorting Algorithms.
STL Common tools for C++.
Pointers and Pointer-Based Strings
ENEE150 Discussion 13 Section 0101 Adam Wang.
Functional Processing of Collections (Advanced)
Starting Out with C++ Early Objects Eighth Edition
Chapter 22: Standard Template Library (STL)
Arrays … The Sequel Applications and Extensions
Introduction to the Standard Template Library
Introduction to LINQ Chapter 11 10/28/2015 Lect 4 CT1411.
Web Systems Development (CSC-215)
Introduction to LINQ Chapter 11.
Object Oriented Programming in java
Selection Insertion and Merge
CS2011 Introduction to Programming I Arrays (I)
24 Searching and Sorting.
Compiler Design Second Lecture.
Pointers and Pointer-Based Strings
Bubble sort.
STL List.
CSCI 3328 Object Oriented Programming in C# Chapter 8: LINQ and Generic Collections – Exercises UTPA – Fall 2012 This set of slides is revised from lecture.
CSE 206 Course Review.
INTRODUCTION to PERL PART 1.
STL List.
Introduction to Computer Science
Selamat Datang di “Programming Essentials in Python”
Presentation transcript:

STL - Algorithms

Imperative vs Declarative Imperative : Do this, then that

Imperative vs Declarative Declarative : Here is what I would like to see

Enhanced For "Enhanced For loop" For loop that does not use indexes Go through vec, grab each element in turn, store it in value and then do this to it

Enhanced For Can use with arrays/strings Declare temp var as & to modify

#include <algorithm> Nonmodifying: algorithms Use iterators to do work to collection

Locators Locating functions return iterator Dereference to get item Subtract starting location to get index

Comparisons == on STL containers tests if contents exactly same equals compares ranges Start at Start1, Go up to End1 Match with things starting at Start 2

UnaryPredicate??? Some algorithms require helper functions to do work count_if needs function to be the "if"

Count If Odd Function name without () = address of function

for_each for_each applies function to range

for_each Use reference parameter to modify values as you go:

Lambdas Lambda See: Anonymous function written inside code Eliminate need for formally defining one of function See: http://www.cprogramming.com/c++11/c++11-lambda-closures.html

Accumulator Accumulate(start, end, value, op ) Do op (default +) to combine each value from start to end with value

Built In Functions Op function can be own: Or a std:: one 

Modifiers Algorithms that modify containers:

Sort Sort using natural ordering ( < )

Sort Change sort criteria with sort function: Take two things, return true if first one goes first Sort using greaterCompare to order:

Sort Criteria Different sort functions for different sorts Sort by age descending: Sort by name ascending:

Remove Remove doesn't actually remove

Remove Remove effect Move values to left to "remove" items Returns iterator pointing to new end of data

Arrays as Targets Can use many algorithms… On arrays On strings Use pointers as iterators On strings Strings have .begin() and .end()