{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

C155-111611-Chap8ArraysSearch

C155-111611-Chap8ArraysSearch - CPT 155 Introduction to...

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

View Full Document Right Arrow Icon
CPT 155  Introduction to Object-Oriented  Programming Objectives: 1. Search arrays Assignments 1. Read Chapter 9 2. Lab 10 due Monday night CNIT 15500, Fall 2011 ©  2011, Alka Harriger  Slide1
Background image of page 1

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

View Full Document Right Arrow Icon
CNIT 15500, Fall 2011 ©  2011, Alka Harriger  Slide2 “Dynamic” Static Arrays: Adding & Searching Adding to the end of the array Use last location variable as index location for array to add data mNbr[mLastLoc] = int.Parse(txtNbr.Text); mName[mLastLoc] = txtName.Text; Add one to the last location variable mLastLoc++; Searching for a value in the array Keep track of match found or not Search from one end of the array until a match is found or you reach the end If match found, show related information If not found, show an appropriate message
Background image of page 2
CNIT 15500, Fall 2011 ©  2011, Alka Harriger  Slide3 // assume searchVal has the value you are seeking bool found = false; // tracks whether search value has been found index = 0; // start with the first location while (index < mLastLoc && found == false) {
Background image of page 3

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

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}