Vectors CSCE 121.

Slides:



Advertisements
Similar presentations
Etter/Ingber Arrays and Matrices. Etter/Ingber One-Dimensional Arrays 4 An array is an indexed data structure 4 All variables stored in an array are of.
Advertisements

C Language.
Introduction to arrays
Chapter 6 Data Structures
Structured Data Types and Encapsulation Mechanisms to create new data types: –Structured data Homogeneous: arrays, lists, sets, Non-homogeneous: records.
Introduction of Arrays. Arrays Array form an important part of almost all programming language. It provides a powerful feature and can be used as such.
Pointers OVERVIEW.
Recap Visual Perception and Data Visualization Types of Information Display Examples of Diagrams used for Data Display Planning Requirement for Data Visualization.
Pointers in C++. 7a-2 Pointers "pointer" is a basic type like int or double value of a pointer variable contains the location, or address in memory, of.
1 One Dimensional Arrays Chapter 11 2 "All students to receive arrays!" reports Dr. Austin. Declaring arrays scores :
Fall 2004CS-183 Dr. Mark L. Hornick 1 C++ Arrays C++ (like Java) supports the concept of collections – mechanisms to sort and manipulate many instances.
Arrays An array is an indexed data structure which is used to store data elements of the same data type. An array is an indexed data structure which is.
Data Types Chapter 6: Data Types Lectures # 11. Topics Introduction Primitive Data Types Character String Types Array Types Associative Arrays Record.
Parameter Passing: Arrays 1.Create new variables (boxes) for each of the formal parameters allocated on a fresh stack created for this function call. int.
CSC 533: Programming Languages Spring 2016
“Generic Programming” ECE 297
CSC 533: Programming Languages Spring 2015
CS 215 Final Review Ismail abumuhfouz Fall 2014.
Motivation and Overview
Hassan Khosravi / Geoffrey Tien
EKT120 : Computer Programming
C Tutorial (part 5) CS220, Spring 2012
COSC 220 Computer Science II
CSE 303 Concepts and Tools for Software Development
Numeric Arrays Numeric Arrays Chapter 4.
STL Common tools for C++.
Lecture 7 – Arrays (1) PGT 106 : C PROGRAMMING.
Hassan Khosravi / Geoffrey Tien
Pointers and References
Dynamic Memory CSCE 121 J. Michael Moore.
This pointer, Dynamic memory allocation, Constructors and Destructor
Collections Intro What is the STL? Templates, collections, & iterators
C++ Data Types Simple Structured Address Integral Floating
Pointers and References
Operator Overloading CSCE 121 J. Michael Moore
C-Programming, continued
C Passing arrays to a Function
Visual Basic .NET BASICS
CS/COE 0449 Jarrett Billingsley
Computer Organization & Compilation Process
Compound Data CSCE 121 J. Michael Moore.
Linked List Intro CSCE 121 J. Michael Moore.
Array & Pointers CSCE 121 J. Michael Moore.
EKT150 : Computer Programming
Pointers and References
CSCI N207 Data Analysis Using Spreadsheet
COMP26120: Algorithms and Imperative programming
EKT120: Computer Programming
STL and Example.
Topics discussed in this section:
Arrays ICS2O.
Vectors.
CS 200 Arrays Jim Williams, PhD.
Vectors CSCE 121 J. Michael Moore.
Exam 2 Exam 2 Regrading Average: 69 TA: Fardad
EECE.2160 ECE Application Programming
TUTORIAL 7 CS 137 F18 October 30th.
Java SE 7 One and Multi Dimensional Arrays Module 6
Data Structures and Algorithms Introduction to Pointers
EECE.2160 ECE Application Programming
Python: Sorting – Selection Sort
COP 3330 Object-oriented Programming in C++
CIS 110: Introduction to Computer Programming
Computer Organization & Compilation Process
point when a program element is bound to a characteristic or property
Collections Intro What is the STL? Templates, collections, & iterators
Linked List Intro CSCE 121.
ENERGY 211 / CME 211 Lecture 10 October 13, 2008.
Operator Overloading CSCE 121 Based on Slides created by Carlos Soto.
Arrays and Pointers.
Presentation transcript:

Vectors CSCE 121

Group of homogeneous elements accessed by an index. Array/Vector Group of homogeneous elements accessed by an index. Vector access with arr.at(index) Bounds checking Array and Vector access with arr[index] No bounds checking

Array Really a pointer Variable name is a pointer to the first element For arr[2] Conceptually: address of arr + 2*sizeof(array datatype) Actually: arr + 2 (math is done automatically) Pointer arithmetic Must know size of array at compile time Allows access to elements outside of array bounds Security problem

Vector Abstraction (An array on the heap.) Preferred over arrays If you use .at() Bounds checking Prevents access outside array bounds Resizable #include <vector>

Vector Must say what type it is e.g. vector<int> Define size at beginning vector<int> vec = vector<int>(SIZE); vector<int> vec = vector<int>(SIZE,INIT_VAL); Let vector grow as needed vector<int> vec; vec.push_back(7); Increases size by one

Vector vector<int> vec; vec.push_back(7); vec.erase(vec.begin()+index); vec.at(index); // range checking & harder to read vec[index]; // no range checking & easier to read

Multi-dimensional Vectors A vector of vectors vector< vector<int> > arr2d; Access arr2d.at(i).at(j) // safer arr2d[i][j]