lecture14

lecture14 - CS111: Intro to Computer Science Lecture 14...

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

View Full Document Right Arrow Icon
CS111: Slides for Prof. Steinberg ʼ s lecture 1 Lecture 14 CS111: Intro to Computer CS111: Intro to Computer Science Science Lecture 14 Asymptotic Complexity
Background image of page 1

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

View Full DocumentRight Arrow Icon
CS111: Slides for Prof. Steinberg ʼ s lecture 2 Lecture 14 Arrays Arrays An array is a group of variables that share a name each also has a unique “index” number Which variable is affected can be the result of a computation 0 33 1 12 2 10 3 1 grades
Background image of page 2
CS111: Slides for Prof. Steinberg ʼ s lecture 3 Lecture 14 Declaring array variables Declaring array variables String [ ] names; Creates a variable to refer to an array Does not create the storage for the array contents. names
Background image of page 3

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

View Full DocumentRight Arrow Icon
CS111: Slides for Prof. Steinberg ʼ s lecture 4 Lecture 14 Creating an Array Creating an Array names = new String [5]; Creates the actual array (but variables still empty) names 0 1 2 3 4 null null null null null
Background image of page 4
CS111: Slides for Prof. Steinberg ʼ s lecture 5 Lecture 14 Uses of arrays Uses of arrays To store an unordered list All that matters is that a piece of data is in the array - doesn’t matter where for (int place = 1; place < names. length; place++){ names[place] = IO.readString( ); } See AboveAvg.java
Background image of page 5

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

View Full DocumentRight Arrow Icon
CS111: Slides for Prof. Steinberg ʼ s lecture 6 Lecture 14 Uses of arrays Uses of arrays To store a growing unordered list When you create the array, you don’t know how large it will grow to be Make it large enough for largest possible Keep track of how large it is / where next item goes Watch out for overflow See ScaleGrades.java (as revised 10/19)
Background image of page 6
CS111: Slides for Prof. Steinberg ʼ s lecture 7 Lecture 14 Uses of arrays Uses of arrays To shrink an unordered list Find item to delete Copy last item over item to delete Remove last item by decrementing place variable Optionally: overwrite last item with null or 0, etc.
Background image of page 7

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

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 11/01/2011 for the course 198 111 at Rutgers.

Page1 / 30

lecture14 - CS111: Intro to Computer Science Lecture 14...

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

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