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.

Slides:



Advertisements
Similar presentations
Chapter 19 Vectors, templates, and exceptions Bjarne Stroustrup
Advertisements

Chapter 18 Vectors and Arrays
SEG4110 – Advanced Software Design and Reengineering TOPIC J C++ Standard Template Library.
Brown Bag #2 Advanced C++. Topics  Templates  Standard Template Library (STL)  Pointers and Smart Pointers  Exceptions  Lambda Expressions  Tips.
Chapter 18 Vectors and Arrays John Keyser’s Modification of Slides by Bjarne Stroustrup
Templates in C++. Generic Programming Programming/developing algorithms with the abstraction of types The uses of the abstract type define the necessary.
Dynamic Memory Allocation (also see pointers lectures) -L. Grewe.
Lecture 3 Feb 4 summary of last week’s topics and review questions (handout) Today’s goals: Chapter 1 overview (sections 1.4 to 1.6) c++ classes constructors,
COMP 171 Data Structures and Algorithms Tutorial 1 Template and STL.
Arrays, Pointers and Structures CS-240 Dick Steflik.
Pointers and Dynamic Variables. Objectives on completion of this topic, students should be able to: Correctly allocate data dynamically * Use the new.
Standard Template Library. Homework List HW will be posted on webpage Due Nov 15.
Prof. amr Goneid, AUC1 CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 11a. The Vector Class.
C++ / G4MICE Course Session 3 Introduction to Classes Pointers and References Makefiles Standard Template Library.
CSIS 123A Lecture 12 Templates. Introduction  C++ templates  Allow very ‘general’ definitions for functions and classes  Type names are ‘parameters’
Review for Midterm Chapter 1-9 CSc 212 Data Structures.
Sorting and Vectors Mechanism for representing lists JPC and JWD © 2002 McGraw-Hill, Inc. Modified by S. Sudarshan.
1 Chapter 3 Lists, Stacks, and Queues Abstract Data Types, Vectors Sections 3.1, 3.2, 3.3, 3.4 Abstract Data Types (ADT) Iterators Implementation of Vector.
1 CSC 222: Computer Programming II Spring 2004 Pointers and linked lists  human chain analogy  linked lists: adding/deleting/traversing nodes  Node.
Generic Positional Containers and Double-Ended Queues.
Introduction to STL and the vector container class CS342 Data Structures Based on Ford & Topp.
Main Index Contents 11 Main Index Contents Week 3 – The Vector Container.
Comp 245 Data Structures Linked Lists. An Array Based List Usually is statically allocated; may not use memory efficiently Direct access to data; faster.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 26: Exam 2 Preview.
Simulated Pointers Limitations Of Java Pointers May be used for internal data structures only. Data structure backup requires serialization and deserialization.
Chapter 9: Part 2: Vectors + Maps and STL Overview JPC and JWD © 2002 McGraw-Hill, Inc. Modified by S. Sudarshan.
Standard Template Library The Standard Template Library was recently added to standard C++. –The STL contains generic template classes. –The STL permits.
Iterator for linked-list traversal, Template & STL COMP171 Fall 2005.
Copyright © 2012 Pearson Education, Inc. Chapter 17: Linked Lists.
3 Data. Software And Data Data Data element – a single, meaningful unit of data. Name Social Security Number Data structure – a set of related data elements.
Templates “Generic Programming” ECE Templates A way to write code once that works for many different types of variables –float, int, char, string,
Lecture 7 : Intro. to STL (Standard Template Library)
A gentle introduction to the standard template library (STL) Some references:
Week 2 - Friday.  What did we talk about last time?  Computing Big Oh.
DATA STRUCTURE & ALGORITHMS Pointers & Structure.
Copyright © 2006 Pearson Addison-Wesley. All rights reserved Today’s Learning Objective  Standard Template Library.
Introduction The STL is a complex piece of software engineering that uses some of C++'s most sophisticated features STL provides an incredible amount.
1 Chapter 3 Lists, Stacks, and Queues Reading: Sections 3.1, 3.2, 3.3, 3.4 Abstract Data Types (ADT) Iterators Implementation of Vector.
A recap of the STL and more containers Plus an intro to string and file input and output! Lecture 8.
Simulated Pointers Limitations Of C++ Pointers May be used for internal data structures only. Data structure backup requires serialization and deserialization.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 20: Container classes; strings.
PROGRAMMING 1 – HELPER INSTRUCTIONS ACKNOWLEDGEMENT: THE SLIDES ARE PREPARED FROM SLIDES PROVIDED BY NANCY M. AMATO AND JORY DENNY 1.
1 Linked Multiple Queues. 2 A real world example. Not in the book. Sometimes we have a fixed number of items that move around among a fixed set of queues.
Standard Template Library a collection of useful tools.
Current Assignments Project 3 has been posted, due next Tuesday. Write a contact manager. Homework 6 will be posted this afternoon and will be due Friday.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 19: Container classes; strings.
1 Generic Positional Containers and Double-Ended Queues.
Data Structures and Algorithm Analysis Dr. Ken Cosh Linked Lists.
CMSC 202 Computer Science II for Majors. CMSC 202UMBC Topics Templates Linked Lists.
Object-Oriented Programming (OOP) Lecture No. 41
Module 20/21/22: The Standard Template Library
“Generic Programming” ECE 297
Lecture 04: Sequences structures
Vectors Holds a set of elements, like an array
ENERGY 211 / CME 211 Lecture 19 November 3, 2008.
Abstract Data Types Iterators Vector ADT Sections 3.1, 3.2, 3.3, 3.4
Object Oriented Programming COP3330 / CGS5409
Linked List Intro CSCE 121 J. Michael Moore.
Chapter 3 Lists, Stacks, and Queues Abstract Data Types, Vectors
Doubly Linked List Implementation
The Standard Template Library
Copyright © – Curt Hill STL List Details Copyright © – Curt Hill.
Java Programming Language
STL (Standard Template Library)
STL List.
Doubly Linked List Implementation
Chapter 3 Lists, Stacks, and Queues
8.3 Vectors Copyright © 2008 Pearson Addison-Wesley. All rights reserved. 1.
STL List.
Presentation transcript:

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 to use containers and algorithms with any type Unlike java even primitives types are supported  E.g. int, float, long

 std::vector v; A resizable array of integers  std::list lNodes; A doubly linked list of Node Pointers  std::queue qPeople; A queue of Person objects  std::deque dStoreQueue; A double ended queue of longs

 T can be any value the vector has been instantiated with  template void vector ::push_back(T const &item) { // resize if necessary new (&d_array[d_size++]) T(item); }  Makes a copy  Behaves the same way as primitives with functions i.e. myfunc(std::vector v) will make a copy.

 std::vector p;  for (int i =0; i < peoplelength; i++) { Person* prsn = new Person(); p.push_back(*prsn) ; //Calls class copy constructor }

.begin() – const iterator .end() – cost iterator

 vector > array2D  push_back(T) //add a value  [-] Where ‘-’ is the integer index //access value by index .clear() and.erase(.begin(),.end() ); //clear the vector Note: Does not remove heap allocated memory such as that assigned with new

.insert(T).push_back(T) .begin(),.end() .front() ->Returns element in front .back()->Returns element behind .pop_back delete last element

 Give us the potential to use templates that make our lives a whole lot easier  Such as random number generators, tuples, threading and Signal/Slots  Hard to understand until you know more about what Templates are  Not 100% supported  Each compiler (g++, visual c) has own specifications

 Basics  #includes  using namespace std; OR used std:: e.g. std::endl; //new line  Code that doesn’t compile (~30%) Syntax Passing correctly to functions  C++ classes  get/set/initialization lists/constructor/destructor  C++ functions passing by reference and value  Problem solving and logic question (~40%)  const will feature a bit