© 2006 Pearson Addison-Wesley. All rights reserved 12.5.1 Arrays of Greater Dimension One-dimensional arrays are linear containers. Multi-dimensional Arrays.

Slides:



Advertisements
Similar presentations
Warm up Determine the value stored in each of the following: – gradeTable[ 0 ][ 0 ] – gradeTable[ 1 ][ 1 ] – gradeTable[ 3 ][ 4 ] – gradeTable[ 5 ][ 2.
Advertisements

Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Fall 2013.
Some containers are called linear because their content (items) are stored in a single row (line). Which of the following are linear?  the rungs of a.
Chapter 9 Arrays. 2 Knowledge Goals Understand the difference between atomic and composite data types Understand the difference between unstructured and.
Slides prepared by Rose Williams, Binghamton University Chapter 6 Arrays.
Arrays part 3 Multidimensional arrays, odds & ends.
Chapter 2 Application Layer. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 2-2.
ECE122 L14: Two Dimensional Arrays March 27, 2007 ECE 122 Engineering Problem Solving with Java Lecture 14 Two Dimensional Arrays.
11-1 Chapter 11 2D Arrays Asserting Java Rick Mercer.
Multidimensional Arrays. Example Write a program to keep track of all warmup scores for all students. Need a list of a list of scores Student – score.
©2004 Brooks/Cole Chapter 8 Arrays. Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Sometimes we have lists of data values that all need to be.
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.
CS102--Object Oriented Programming Lecture 6: – The Arrays class – Multi-dimensional arrays Copyright © 2008 Xiaoyan Li.
Chapter 6 Human Capital. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 6-2.
Lab 11 rArrays rExercises Note: Read the whole Chapter 8.
Building Java Programs Chapter 7.5
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 7 Multidimensional.
Chapter 16 Resources and the Environment at the Global Level.
© 2011 Pearson Education, publishing as Addison-Wesley 1 Arrays  Arrays are objects that help us organize large amounts of information  Chapter 6 focuses.
CPS120: Introduction to Computer Science Arrays. Arrays: A Definition A list of variables accessed using a single identifier May be of any data type Can.
Chapter 7 Arrays. © 2004 Pearson Addison-Wesley. All rights reserved11-2 Arrays Arrays are objects that help us organize large amounts of information.
JAVA: An Introduction to Problem Solving & Programming, 7 th Ed. By Walter Savitch ISBN © 2015 Pearson Education, Inc., Upper Saddle River,
Lecture Contents Arrays and Vectors: Concepts of array. Memory index of array. Defining and Initializing an array. Processing an array. Parsing an array.
Chapter 8 Arrays Part II J. H. Wang ( 王正豪 ), Ph. D. Assistant Professor Dept. Computer Science and Information Engineering National Taipei University of.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Searching Arrays Searching.
Programming Fundamentals I (COSC-1336), Lecture 8 (prepared after Chapter 7 of Liang’s 2011 textbook) Stefan Andrei 4/23/2017 COSC-1336, Lecture 8.
When constructing a two-dimensional array, specify how many rows and columns are needed: final int ROWS = 3; final int COLUMNS = 3; String[][] board =
Liang, Introduction to Java Programming, Tenth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 8 Multidimensional Arrays.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 8 Multidimensional Arrays Lecture.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 7 Multidimensional.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved
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.
© 2004 Pearson Addison-Wesley. All rights reserved October 13, D Arrays ComS 207: Programming I (in Java) Iowa State University, FALL 2006 Instructor:
© Copyright 2013 by Pearson Education, Inc. All Rights Reserved. 1 Chapter 8 Multidimensional Arrays.
M180: Data Structures & Algorithms in Java Arrays in Java Arab Open University 1.
Computer Science: A Structured Programming Approach Using C1 8-7 Two-Dimensional Arrays The arrays we have discussed so far are known as one- dimensional.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
© 2004 Pearson Addison-Wesley. All rights reserved October 15, 2007 Searching ComS 207: Programming I (in Java) Iowa State University, FALL 2007 Instructor:
Data Structure CS 322. What is an array? Initializing arrays Accessing the values of an array Multidimensional arrays LAB#1 : Arrays.
CPS120: Introduction to Computer Science Lecture 15 Arrays.
CMSC 202 Arrays 2 nd Lecture. Aug 6, Array Parameters Both array indexed variables and entire arrays can be used as arguments to methods –An indexed.
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
Get Longest Run Index (FR) public int getLongestRunIndex(int []values) { int maxRunStart = -1, maxRunLength = 1; int runStart = 0, runLength = 1; for(int.
COMP More About Arrays Yi Hong June 05, 2015.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Arrays (part 2) 1 -Based on slides from Deitel & Associates, Inc. - Revised by T. A. Yang.
Two-Dimensional Arrays. Two-dimensional arrays variables store the contents of tables or matrices. Example: Dim arrTable(1 to 5, 1 to 5) As Integer first.
Multidimensional Arrays Vectors of Vectors When One Is Not Enough.
Multidimensional Arrays tMyn1 Multidimensional Arrays It is possible to declare arrays that require two or more separate index values to access an element.
 Introducing Arrays  Declaring Array Variables, Creating Arrays, and Initializing Arrays  Copying Arrays  Multidimensional Arrays  Search and Sorting.
Arrays Declaring arrays Passing arrays to functions Searching arrays with linear search Sorting arrays with insertion sort Multidimensional arrays Programming.
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 ARRAYS 1. Multi-dimensional Arrays The types of arrays discussed so far are all linear arrays. That is, they all dealt with a single.
Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 6 Multidimensional.
COMP 110: Spring Announcements Lab 7 was due today Binary Expression Assignment due Friday.
ARRAYS Multidimensional realities Image courtesy of
COMP 110 More arrays, 2D arrays, Program 4 Luv Kohli November 10, 2008 MWF 2-2:50 pm Sitterson 014.
© 2004 Pearson Addison-Wesley. All rights reserved7-1 Array review Array of primitives int [] count; count = new int[10]; Array of objects Grade [] cs239;
Two-dimensional Arrays two-dimensional arrays are often used to represent tables of values consisting of data arranged in rows and columns (Fig. 7.16).
 2005 Pearson Education, Inc. All rights reserved Arrays.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 7A Arrays (Concepts)
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 7 Multidimensional Arrays.
LESSON 8: INTRODUCTION TO ARRAYS. Lesson 8: Introduction To Arrays Objectives: Write programs that handle collections of similar items. Declare array.
1 Arrays and Variable Length Parameter List  The syntax to declare a variable length formal parameter (list) is: dataType... identifier.
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 Array Mr. Jacobs.
Multidimensional Arrays
Multidimensional Arrays
Presentation transcript:

© 2006 Pearson Addison-Wesley. All rights reserved Arrays of Greater Dimension One-dimensional arrays are linear containers. Multi-dimensional Arrays [0] [1] [2] [0] [0] [1] [2] [3] [1] [2] two-dimensional [0] [0] [1] [2] [3] [4] [1] [2] [3] [2] [1] [0] three-dimensional

© 2006 Pearson Addison-Wesley. All rights reserved Initializing Multi-dimensional Arrays [0] [0] [1] [2] [3] [1] [2] [0] [0] [1] [2] [3] [4] [1] [2] [3] [2] [1] [0] [0] [1] [2] declarationinstantiation Oval[] circles;circles = ; double[][] table;table = int[][][] arr;arr =

© 2006 Pearson Addison-Wesley. All rights reserved double[][] distance = new double[10][15]; int[][][] cube = new int[8][8][10]; How many cells in each of the following? String[][][][][] words = new String[5][4][5][12][6];

© 2006 Pearson Addison-Wesley. All rights reserved Creating Multi-dimensional Arrays The initialization notation for 1D arrays can be extended. char[][] words = { {'c', 'i', 'p', 'h', 'e', 'r'}, {'h', 'i', 'c', 'c’, 'u', 'p'}, {'a', 'p', 'i', 't', 'c', 'h'} }; [0] [0] [1] [2] [3] [4] [5] [1] [2] How would you duplicate this behavior without the initialization notation? Exercise

© 2006 Pearson Addison-Wesley. All rights reserved Processing Multi-dimensional Arrays The key to processing all cells of a multi-dimensional array is nested loops. [0] [1] [2] [3] [0] [1] [2] [3] [4] for (int row=0; row!=5; row++) { for (int col=0; col!=4; col++) { System.out.println( myArray[row][col] ); } for (int col=0; col!=4; col++) { for (int row=0; row!=5; row++) { System.out.println( myArray[row][col] ); } 1) Write a method to initialize this array with the given values. 2) Write a method to interchange two columns, indexed by two int parameters. Exercises

© 2006 Pearson Addison-Wesley. All rights reserved Tables private final int[] mileage = {{0, 722, 2244, 800, 896}, {722, 0, 1047, 2113, 831}, {2244, 1047, 0, 1425, 1576}, {800, 2113, 1425, 0, 2849, {896, 831, 1576, 2849, 0} }; private final int atlanta = 0; private final int chicago = 1; private final int dallas = 2; private final int losAngelas = 3; private final int newYork = 4;