Arrays Array – Group of contiguous memory locations Each memory location has same name Each memory location has same type.

Slides:



Advertisements
Similar presentations
Chapter 21 Implementing lists: array implementation.
Advertisements

UNIT IV.
Introduction to Java 2 Programming Lecture 5 Array and Collections.
Copyright © 2002 Pearson Education, Inc. Slide 1.
Introduction to C Programming
Arrays.
1 Arrays Chapter 9. 2 Outline  The array structure (Section 9.1)  Array declaration  Array initialization  Array subscripts  Sequential access to.
 2006 Pearson Education, Inc. All rights reserved Arrays.
 2003 Prentice Hall, Inc. All rights reserved. 7.1 Introduction Arrays –Data structures which reference one or more value –All items must have same data.
5 5 Arrays. OBJECTIVES In this lecture we will learn:  Case switch  To use the array data structure to represent a set of related data items.  To declare.
Programming with Collections Collections in Java Using Arrays Week 9.
Arrays  Writing a program that uses a large amount of information.  Such as a list of 100 elements.  It is not practical to declare.
Arrays Chapter 6.
 2003 Prentice Hall, Inc. All rights reserved. Chapter 7 - Arrays Outline 7.1 Introduction 7.2 Arrays 7.3 Declaring and Creating Arrays 7.4 Examples Using.
 2005 Pearson Education, Inc. All rights reserved Arrays.
COMP 110 Introduction to Programming Mr. Joshua Stough October 24, 2007.
 2003 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to Arrays Introduction to Computers and Programming in.
1 CSCE 1030 Computer Science 1 Arrays Chapter 7 in Small Java.
 Pearson Education, Inc. All rights reserved Arrays.
1 JavaScript/Jscript: Arrays. 2 Introduction Arrays –Data structures consisting of related data items (collections of data items) JavaScript arrays are.
 2006 Pearson Education, Inc. All rights reserved Arrays.
Arrays. Introduction This chapter serves as an introduction to the important topic of data structures. Arrays are data structures consisting of related.
CHAPTER 07 Arrays and Vectors (part I). OBJECTIVES 2 In this part you will learn:  To use the array data structure to represent a set of related data.
Arrays Chapter 7. 2 "All students to receive arrays!" reports Dr. Austin. Declaring arrays scores : Inspecting.
Introduction to Arrays in Java Corresponds with Chapter 6 of textbook.
 2005 Pearson Education, Inc. All rights reserved. 1 Arrays Part 4.
ARRAYS 1 Week 2. Data Structures  Data structure  A particular way of storing and organising data in a computer so that it can be used efficiently 
 Pearson Education, Inc. All rights reserved Arrays.
 2005 Pearson Education, Inc. All rights reserved. 1 Arrays.
 Pearson Education, Inc. All rights reserved Arrays.
What is an Array? An array is a collection of variables. Arrays have three important properties: –group of related items(for example, temperature for.
Arrays, File Access, and Plotting
Chapter 8: Arrays.
Chapter 7 Arrays. A 12-element array Declaring and Creating Arrays Arrays are objects that occupy memory Created dynamically with keyword new int c[]
Java Script: Arrays (Chapter 11 in [2]). 2 Outline Introduction Introduction Arrays Arrays Declaring and Allocating Arrays Declaring and Allocating Arrays.
Array Cs212: DataStructures Lab 2. Array Group of contiguous memory locations Each memory location has same name Each memory location has same type a.
Arrays Chapter 8. What if we need to store test scores for all students in our class. We could store each test score as a unique variable: int score1.
Java™ How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
1 Mr. Muhammad Hanif Lecturer Information Technology MBBS Campus Dadu University of SIndh.
 2005 Pearson Education, Inc. All rights reserved Arrays.
Array, Structure and Union
Week # 2: Arrays.  Data structure  A particular way of storing and organising data in a computer so that it can be used efficiently  Types of data.
 Pearson Education, Inc. All rights reserved Arrays.
Method Overloading  Methods of the same name can be declared in the same class for different sets of parameters  As the number, types and order of the.
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
Arrays Chapter 7. 2 Declaring and Creating Arrays Recall that an array is a collection of elements all of the _____________ Array objects in Java must.
Arrays Declaring arrays Passing arrays to functions Searching arrays with linear search Sorting arrays with insertion sort Multidimensional arrays Programming.
SEQUENTIAL AND OBJECT ORIENTED PROGRAMMING Arrays.
Array contiguous memory locations that have the same name and type. Note: an array may contain primitive data BUT an array is a data structure a collection.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved. - Edited By: Maysoon Al-Duwais 1.
1 CSC103: Introduction to Computer and Programming Lecture No 17.
 2005 Pearson Education, Inc. All rights reserved Arrays.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 7A Arrays (Concepts)
 2006 Pearson Education, Inc. All rights reserved Arrays and Vectors.
Introduction to programming in java Lecture 21 Arrays – Part 1.
Lecture 4: Chapter 7 - Arrays Outline Declaring and Creating Arrays Examples Using Arrays References and Reference Parameters Passing Arrays to Methods.
Arrays 1.
ARRAYS (Extra slides) Arrays are objects that help us organize large amounts of information.
Arrays Chapter 7.
© 2016 Pearson Education, Ltd. All rights reserved.
8 Arrays.
Review of Arrays and Pointers
7 Arrays.
Cs212: Data Structures Computer Science Department Lecture 2: Arrays.
MSIS 655 Advanced Business Applications Programming
Data Structures (CS212D) Week # 2: Arrays.
Arrays Chapter 7.
Arrays Week 2.
JavaScript: Arrays.
Presentation transcript:

Arrays Array – Group of contiguous memory locations Each memory location has same name Each memory location has same type

A 12-element array c[ 1 ] c[ 2 ] c[ 4 ] c[ 3 ] c[ 5 ] c[ 6 ] c[ 7 ] c[ 8 ] c[ 9 ] c[ 10 ] c[ 11 ] c[ 0 ] Name of array (Note that all elements of this array have the same name, c ) Position number (index of subscript) of the element within array c

Arrays (cont.) Examine array c – c is the array name – c.length accesses array c ’s length – c has 12 elements ( c[0], c[1], … c[11] ) The value of c[0] is –45 The brackets ( [] ) are in highest level of precedence in Java

Declaring and Allocating Arrays Declaring and Allocating arrays – Arrays are objects that occupy memory – Allocated dynamically with operator new int c[] = new int[ 12 ]; – Equivalent to int c[]; // declare array c = new int[ 12 ]; // allocate array We can allocate arrays of objects too String b[] = new String[ 100 ];

Allocating an Array and Initializing Its Elements Show how to – Declare array – Allocate array – Initialize array elements

Declare array as an array of int s Allocate 10 int s for array ; each int is initialized to 0 by default array.length returns length of array array[counter] returns int associated with index in array

Each int is initialized to 0 by default

Using an Initializer List to Initialize Elements of an Array Initialize array elements – Use initializer list Items enclosed in braces ( {} ) Items in list separated by commas int n[] = { 10, 20, 30, 40, 50 }; – Creates a five-element array – Subscripts of 0, 1, 2, 3, 4 – Do not need operator new

Each array element corresponds to element in initializer list

Examples

Calculating the Value to Store in Each Array Element Calculate value stored in each array element – Initialize elements of 10-element array to even integers

Summing the Elements of an Array Array elements – Can represent a series of values We can sum these values

Using Histograms to Display Array Data Graphically Present array values graphically – Histogram Plot each numeric value as bar of asterisks ( * )