lecture10-feb10 - Announcements - Lecture 10 Assignment 2...

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

View Full Document Right Arrow Icon
1 Announcements - Lecture 10 • Assignment 2 – Q&A – due tomorrow – Count the number of statements in your code and write that down too • Assignment 3 out next week – 2 parts • Exam 1 a week from Friday in class (Ch. 1-9) • Topics for today – More Arrays 1D • search, insert,delete,parallel,sort – 2D, 3D… Recall last time: Arrays 1D Partially flled Unordered Ordered Common algorithms Exam scores example Find the Smallest Value /* goal - find the lowest score in the exam1Scores array */ #define CLASS_SIZE 142 . . . int exam1Scores [CLASS_SIZE ], numberOfStudents; int i, smallestIndex = 0; /* assume that the array gets filled with values in here */ /* assume that numberOfStudents holds the actual # of students */ /* start search by assuming that the 0th element is the smallest */ for (i= 1; i < numberOfStudents; i++) if (exam1Scores[i] < exam1Scores[smallestIndex]) {smallestIndex = i;} /* replace current smallest index with smaller one’s index */ printf (“ the lowest score found was: %d \n”, exam1Scores [smallestIndex]); . . . printF (“enter the # oF students\n”); scanF (“%d”, &numberOFStudents); For (i=0; i< numberOFStudents; i++) { printF (“enter the next score:\n”); scanF (“%d”, &exam1scores [i]); } Adding and Removing Values in unordered arrays (partially filled) Add - for unordered arrays you can just add a new value (say newScore) onto the end exam1scores [numberOfStudents +1] = newScore; numberOfStudents ++; Remove - for unordered arrays you can replace the value to be removed with the last value exam1scores [removeIndex] = exam1scores [numberOfStudents]; numberOfStudents --; Removing a Value from an Ordered Array All subsequent values must move up one element beFore aFter Value Inserting a Value into an Ordered Array All subsequent values must be moved down to make room beFore aFter Value Array Array Parallel Arrays For example, grades1 and grades2
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Parallel Arrays This code counts the number of students whose
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 5

lecture10-feb10 - Announcements - Lecture 10 Assignment 2...

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

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