{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lecture14

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

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

CS111: Slides for Prof. Steinberg ʼ s lecture 1 Lecture 14 CS111: Intro to Computer CS111: Intro to Computer Science Science Lecture 14 Asymptotic Complexity

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

View Full Document
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
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

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

View Full Document
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
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

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

View Full Document
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)
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.

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### 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
Ask a homework question - tutors are online