Multidimensional Arrays Vectors of Vectors When One Is Not Enough.

Slides:



Advertisements
Similar presentations
Arrays.
Advertisements

Two-Dimensional Arrays Chapter What is a two-dimensional array? A two-dimensional array has “rows” and “columns,” and can be thought of as a series.
Topic 9C – Multiple Dimension Arrays. CISC105 – Topic 9C Multiple Dimension Arrays A multiple dimension array is an array that has two or more dimensions.
1 ICS103 Programming in C Lecture 16: 2-Dimensional Arrays.
Slides prepared by Rose Williams, Binghamton University Chapter 6 Arrays.
Arrays part 3 Multidimensional arrays, odds & ends.
ECE122 L14: Two Dimensional Arrays March 27, 2007 ECE 122 Engineering Problem Solving with Java Lecture 14 Two Dimensional Arrays.
#include using namespace std; void main() { int a[3]={10,11,23}; for(int i=0;i
Computer programming 1 Multidimensional Arrays, and STL containers: vectors and maps.
Computer Science 1620 Multi-Dimensional Arrays. we used arrays to store a set of data of the same type e.g. store the assignment grades for a particular.
1 Arrays  Arrays are objects that help us organize large amounts of information  Chapter 8 focuses on: array declaration and use passing arrays and array.
 2003 Prentice Hall, Inc. All rights reserved. 1 Arrays –Structures of related data items –Static entity (same size throughout program) A few types –Pointer-based.
Multiple-Subscripted Array
1 CS 201 Array Debzani Deb. 2 Having trouble linking math.h? Link with the following option gcc –lm –o test test.o.
C++ for Engineers and Scientists Third Edition
CSE202: Lecture 16The Ohio State University1 Two Dimensional Arrays.
Building Java Programs Chapter 7.5
Chapter 9 Introduction to Arrays
Arrays (Part II). Two- and Multidimensional Arrays Two-dimensional array: collection of a fixed number of components (of the same type) arranged in two.
1 Arrays & functions Each element of an array acts just like an ordinary variable: Like any ordinary variable, you can pass a single array element to a.
Chapter 8 Multidimensional Arrays C Programming for Scientists & Engineers with Applications by Reddy & Ziegler.
Prepared by MURLI MANOHAR PGT (COMPUTER SCIENCE) KV,B.E.G., PUNE.
Java Unit 9: Arrays Declaring and Processing Arrays.
Chapter 6Java: an Introduction to Computer Science & Programming - Walter Savitch 1 l Array Basics l Arrays in Classes and Methods l Programming with Arrays.
Chapter 7: Arrays. In this chapter, you will learn about: One-dimensional arrays Array initialization Declaring and processing two-dimensional arrays.
JAVA: An Introduction to Problem Solving & Programming, 7 th Ed. By Walter Savitch ISBN © 2015 Pearson Education, Inc., Upper Saddle River,
1 DATA STRUCTURES: LISTS. 2 LISTS ARE USED TO WORK WITH A GROUP OF VALUES IN AN ORGANIZED MANNER. A SERIES OF MEMORY LOCATIONS CAN BE DIRECTLY REFERENCED.
Lecture Contents Arrays and Vectors: Concepts of array. Memory index of array. Defining and Initializing an array. Processing an array. Parsing an array.
Two dimensional arrays in Java Computer Science 3 Gerb Objective: Use matrices in Java.
ARRAYS Computer Engineering Department Java Course Asst. Prof. Dr. Ahmet Sayar Kocaeli University - Fall
CHAPTER: 12. Array is a collection of variables of the same data type that are referenced by a common name. An Array of 10 Elements of type double.
CPSC 252 Concrete Data Types Page 1 Overview of Concrete Data Types There are two kinds of data types: Simple (or atomic) – represents a single data item.
© 2004 Pearson Addison-Wesley. All rights reserved October 13, D Arrays ComS 207: Programming I (in Java) Iowa State University, FALL 2006 Instructor:
Computer Programming 12 Mr. Jean April 24, The plan: Video clip of the day Upcoming Quiz Sample arrays Using arrays More about arrays.
C++ for Engineers and Scientists Second Edition Chapter 11 Arrays.
Arrays & Vectors Week 5. The simplest form of the multidimensional array is the two-dimensional array. A two- dimensional array is, in essence, a list.
Chapter overview This chapter focuses on Array declaration and use Bounds checking and capacity Arrays storing object references Variable length parameter.
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
Chapter 6Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 6 l Array Basics l Arrays in Classes and Methods l Programming.
Lec 13 Oct 21, 02. Array Initialization in the declaration statement ► int temp[5] = {98, 87, 92, 79,85}; ► char codes[6] = { ‘s’, ’a’, ‘m’, ‘p’, ‘l’,
Arrays.
Chapter 8: Part 3 Collections and Two-dimensional arrays.
Multidimensional Arrays tMyn1 Multidimensional Arrays It is possible to declare arrays that require two or more separate index values to access an element.
C++ Array 1. C++ provides a data structure, the array, which stores a fixed-size sequential collection of elements of the same type. An array is used.
ADVANCED POINTERS. Overview Review on pointers and arrays Common troubles with pointers Multidimensional arrays Pointers as function arguments Functions.
Multi-dimensional Array 1 Multi-dimensional array refers to an array with more than one index. It is a logical representation. On physical storage, the.
MULTI-DIMENSIONAL ARRAYS 1. Multi-dimensional Arrays The types of arrays discussed so far are all linear arrays. That is, they all dealt with a single.
COMP 110: Spring Announcements Lab 7 was due today Binary Expression Assignment due Friday.
Lecture 9 – Array (Part 2) FTMK, UTeM – Sem /2014.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 7A Arrays (Concepts)
CS 201 Tarik Booker California State University, Los Angeles.
Chapter 9 Introduction to Arrays Fundamentals of Java.
Two-Dimensional Data Class of 5 students Each student has 3 test scores Store this information in a two- dimensional array First dimension: which student.
1 Multidimensional Arrays Chapter 13 2 The plural of mongoose starts with a "p" Initializing a multidimensional array Processing by.
Chapter 8 Arrays and the ArrayList Class Multi-Dimensional Arrays.
Arrays 4/4 By Pius Nyaanga. Outline Multidimensional Arrays Two-Dimensional Array as an Array of Arrays Using the length Instance Variable Multidimensional.
Two-Dimensional Arrays
Multidimensional Arrays
Two Dimensional Arrays
Two Dimensional Array Mr. Jacobs.
Multi-dimensional Array
Programming -2 برمجة -2 المحاضرة-5 Lecture-5.
Repeating Instructions And Advance collection
Multidimensional Arrays Vectors of Vectors
CSCI N207 Data Analysis Using Spreadsheet
Multidimensional Arrays
Chapter 7 Part 2 Edited by JJ Shepherd
Multidimensional array
Multidimensional Arrays
Arrays Arrays A few types Structures of related data items
Presentation transcript:

Multidimensional Arrays Vectors of Vectors When One Is Not Enough

Two Dimensional Array Basics l matrices, tables and similar information is often naturally represented by a two-dimensional array n first index – row n second index - column l declaration: basicType arrayName[rows][columns]; example int a[3][4]; l accessing a[0][1] = 23; cout << a[1][3]; c[2][4]+=55; l either index out of range is still an error a[2][4] = 55; // error larger dimensions are possible: int b[10][100][200]; 2

Two Dimensional Arrays in Loops nested loops are useful with multidimensional arrays for (int i=0; i < length; ++i) for (int j=0; j < width; ++j) cout << a[i][j] << ” ”; 3

Arrays and Functions l if multidimensional array is used as parameters, all but first dimension have to be stated l the first dimension can be passed as separate parameter const int WIDTH=2; void printArray(int c[][WIDTH], int length){ for (int i=0; i < length; ++i) for (int j=0; j < WIDTH; ++j) cout << c[i][j] << ” ”; } 4

Vectors of Vectors l alternative to multidimensional arrays l outer vector’s type is declared to be a vector vector > a; l inner vectors can then be added to the outer vector vector row(width); for(int i=0; i < length; ++i) a.push_back(row); l vector elements can be accessed as in array for (int i=0; i < length; ++i) for (int j=0; j < width; ++j) cout << a[i][j] << ” ”; l vectors retain all advantage over arrays: has extra functions, carry size, can pass by value/return, can change size on demand l moreover: can create ragged (jagged) arrays – rows can vary in size 5

Review Questions l Why are multidimensional arrays necessary? l How does one declare a two-dimensional array? l What is the first index? the second index? l How does one access an element of multidimensional array? l Why are nested loops useful with multidimensional arrays? l How is multidimensional array passed as a parameter to a function? l What is vector of vectors? l How does one declare a vector of vectors? Initialize it? l How are individual elements of a vector of vectors accessed? l What are the advantages of a vector of vectors over multidimensional array? l What is ragged/jagged array? 6