Chapter 8 Arrays, Strings and pointers

Slides:



Advertisements
Similar presentations
11 Copyright © 2005, Oracle. All rights reserved. Using Arrays and Collections.
Advertisements

Data Structures Using C++ 2E
Beginning C++ Through Game Programming, Second Edition
Array Lists Chapter 7.2 Pages Array Lists In Java, Arrays are an important structure for storing data. We will learn more about arrays later,
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Sixth Edition Chapter 17: Linked Lists.
More on the STL vector list stack queue priority_queue.
Main Index Contents 11 Main Index Contents Container Types Container Types Sequence Containers Sequence Containers Associative Containers Associative Containers.
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 17 Linked.
Prof. amr Goneid, AUC1 CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 11a. The Vector Class.
Data Structures Using C++ 2E
Searching and Sorting, Template Functions, and Vectors ITK 169 Fall 2003.
Generic Programming Using the C++ Standard Template Library.
Aug 9, CMSC 202 ArrayList. Aug 9, What’s an Array List ArrayList is  a class in the standard Java libraries that can hold any type of object.
Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy Walters, and Godfrey Muganda Chapter 17: Linked Lists.
Arrays Adapted from materials created by Dr. Donald Bell, Cal Poly 2000 (updated February 2004)
The median again The steps of our algorithm: Read the size of the list, N. Declare and instantiate an array of integers, "list". Read the elements of list.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 7 Arrays.
Introduction The STL is a complex piece of software engineering that uses some of C++'s most sophisticated features STL provides an incredible amount.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy.
Chapter 7 Arrays Csc 125 Introduction to C++. Topics Arrays Hold Multiple Values Array Operations Arrays as function arguments Two-dimensional arrays.
Glenn Stevenson CSIS 113A MSJC CSIS 123A Lecture 3 Vectors.
PROGRAMMING 1 – HELPER INSTRUCTIONS ACKNOWLEDGEMENT: THE SLIDES ARE PREPARED FROM SLIDES PROVIDED BY NANCY M. AMATO AND JORY DENNY 1.
Chapter 17 – Templates. Function Templates u Express general form for a function u Example: template for adding two numbers Lesson 17.1 template Type.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy.
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Eighth Edition by Tony Gaddis,
C Programming Lecture 15 Two Dimensional Arrays. Two-Dimensional Arrays b The C language allows arrays of any type, including arrays of arrays. With two.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 18: Stacks and Queues.
Module 20/21/22: The Standard Template Library
CMSC 202 ArrayList Aug 9, 2007.
Chapter 7 – Arrays and Array Lists
Chapter 18: Stacks and Queues.
Principles of programming languages 8: Types
Fundamentals of Java: AP Computer Science Essentials, 4th Edition
Vectors Holds a set of elements, like an array
CSCE 210 Data Structures and Algorithms
Dr. Bernard Chen Ph.D. University of Central Arkansas
ARRAYLIST AND VECTOR.
STL Common tools for C++.
Array Array is a variable which holds multiple values (elements) of similar data types. All the values are having their own index with an array. Index.
Arrays and the ArrayList Class The ArrayList Class
Chapter-7 part3 Arrays Two-Dimensional Arrays The ArrayList Class.
Starting Out with C++ Early Objects Eighth Edition
Hash table another data structure for implementing a map or a set
Chapter 19: Stacks and Queues.
Object Oriented Programming COP3330 / CGS5409
Chapter 18: Linked Lists.
Vectors.
ArrayLists.
C++ STL Vector Container
Chapter 13 Collections.
Chapter 8 Slides from GaddisText
CMSC 202 ArrayList Aug 9, 2007.
Chapter 17: Linked Lists Starting Out with C++ Early Objects
Chapter 8 Collection Types.
Object Oriented Programming in java
CMSC 202 ArrayList Aug 9, 2007.
C-to-LC3 Compiler Over the course of the next two weeks, you will build a program that will compile C code to LC-3 assembly language Don't panic! You.
MSIS 655 Advanced Business Applications Programming
Standard Version of Starting Out with C++, 4th Edition
Chapter 17: Linked Lists.
CIS 199 Final Review.
Dr. Sampath Jayarathna Cal Poly Pomona
ArrayLists 27-Apr-19.
COP 3330 Object-oriented Programming in C++
STL (Standard Template Library)
C++ Programming: chapter 10 – STL
the Standard Template Library
ENERGY 211 / CME 211 Lecture 10 October 13, 2008.
The List Container and Iterators
Introduction to Computer Science
Presentation transcript:

Chapter 8 Arrays, Strings and pointers 8c: Vector (array)

Chapter Goals: To learn basic concept of vector To learn how to access vector To grow or shrink vector To apply vector using function To develop vector algorithm

8.1 Concepts the size of the array has to be known when the program is compiled. A vector collects a sequence of values, just like an array does, but its size can change (more convenient than partial filled array) A vector expands to hold as many elements as needed

8.2 Define Example:

Use bracket to access vector element Just like you do with array Size member function to obtain current size of vector

8.2 Access Vector push_back Example 1: Example 2: add element to the end of vector, increasing size by 1. Example 1: Example 2:

8.2 Access Vector pop_back Example: Removes the last element of vector, shrinking size by 1. Example:

8.3 Vector & Function Vectors can occur as function arguments and return values. Use a reference parameter to modify the contents of a vector. a function can return a vector

8.4 Vector Algorithm Refer textbook p288.

Exercise 35. vector <int> primeNum; primeNum.push_back(2); 36. vector <int> primeNum(5); primeNum[0] = 2; primeNum[1] = 3; primeNum[2] = 5; primeNum[3] = 7; primeNum[4] = 11; 37. Ann Cal

Exercise