26.07.2013 Views

Java How to Program Fourth Edition - DCC

Java How to Program Fourth Edition - DCC

Java How to Program Fourth Edition - DCC

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

314 Arrays Chapter 7<br />

Outline<br />

7.1 Introduction<br />

7.2 Arrays<br />

7.3 Declaring and Allocating Arrays<br />

7.4 Examples Using Arrays<br />

7.4.1 Allocating an Array and Initializing Its Elements<br />

7.4.2 Using an Initializer List <strong>to</strong> Initialize Elements of an Array<br />

7.4.3 Calculating the Value <strong>to</strong> S<strong>to</strong>re in Each Array Element<br />

7.4.4 Summing the Elements of an Array<br />

7.4.5 Using His<strong>to</strong>grams <strong>to</strong> Display Array Data Graphically<br />

7.4.6 Using the Elements of an Array as Counters<br />

7.4.7 Using Arrays <strong>to</strong> Analyze Survey Results<br />

7.5 References and Reference Parameters<br />

7.6 Passing Arrays <strong>to</strong> Methods<br />

7.7 Sorting Arrays<br />

7.8 Searching Arrays: Linear Search and Binary Search<br />

7.8.1 Searching an Array with Linear Search<br />

7.8.2 Searching a Sorted Array with Binary Search<br />

7.9 Multiple-Subscripted Arrays<br />

7.10 (Optional Case Study) Thinking About Objects: Collaboration<br />

Among Objects<br />

Summary • Terminology • Self-Review Exercises • Answers <strong>to</strong> Self-Review Exercises • Exercises •<br />

Recursion Exercises • Special Section: Building Your own Computer<br />

7.1 Introduction<br />

This chapter serves as an introduction <strong>to</strong> the important <strong>to</strong>pic of data structures. Arrays are<br />

data structures consisting of related data items of the same type. Arrays are “static” entities,<br />

in that they remain the same size once they are created, although an array reference may be<br />

reassigned <strong>to</strong> a new array of a different size. Chapter 19, “Data Structures,” introduces dynamic<br />

data structures, such as lists, queues, stacks and trees, that can grow and shrink as<br />

programs execute. Chapter 20, “<strong>Java</strong> Utilities Package and Bit Manipulation,” discusses<br />

class Vec<strong>to</strong>r, which is an array-like class whose objects can grow and shrink in response<br />

<strong>to</strong> a <strong>Java</strong> program’s changing s<strong>to</strong>rage requirements. Chapter 21, “The Collections API,” introduces<br />

<strong>Java</strong>’s predefined data structures that enable the programmer <strong>to</strong> use existing data<br />

structures for lists, queues, stacks and trees rather than “reinventing the wheel.” The Collections<br />

API also provides class Arrays, which defines a set of utility methods for array<br />

manipulation.<br />

© Copyright 1992–2002 by Deitel & Associates, Inc. All Rights Reserved. 7/3/01

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!