lec19 - Lecture 19 Returning Arrays Partially filled arrays...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
CS125 Course Notes Lecture 19, Slide 1 Lecture 19 • Returning Arrays • Partially filled arrays • Searching • Sorting (Savitch 6.3, 6.4)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS125 Course Notes Lecture 19, Slide 2 Last Day • We discussed the BirthdayArray class • Created arrays of objects • Passed them as parameters • Modified contents of array in a method
Background image of page 2
CS125 Course Notes Lecture 19, Slide 3 Arrays as return types • Write a method createSelection • Works like printSelection (from last day), but creates an array with the selected entries and returns it.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS125 Course Notes Lecture 19, Slide 4 Returning an array from a method • Create an array of the appropriate size • Initialize all array entries for the new array • Use return statement • Method return type should be BaseType []
Background image of page 4
CS125 Course Notes Lecture 19, Slide 5 Arrays as return types continued public Date[] createSelection(int[] whichOne) { Date[] smallerArray = new Date[whichOne.length]; for (int i = 0; i < whichOne.length; i++) { smallerArray[i] = this.birthday[whichOne[i]]; } return smallerArray; }
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS125 Course Notes Lecture 19, Slide 6 Arrays as return types – memory model 2122 25 birthday[0].day 2118 12 birthday[0].month
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 07/27/2009 for the course MATH 135 taught by Professor Andrewchilds during the Fall '08 term at Waterloo.

Page1 / 22

lec19 - Lecture 19 Returning Arrays Partially filled arrays...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online