DOC PREVIEW
Saddleback CS 1B - Searching & Sorting

This preview shows page 1-2 out of 7 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 7 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 7 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 7 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

10-1Chapter 10Searching & Sorting10-2Sequential Search (list does not need to be ordered)Sequential Searchindex = 0found = false while!found && index < size ifa[index] == keyfound = trueindex ++endTFTFMEMORIZE THIS ALGORITHM10-3Binary Search (ordered lists only)BinarySearchfound = falsebott = 0top = size - 1 while!found && bott <= topmid = (bott + top) / 2 ifa[mid] == keyfound = true ifa[mid] < keybott = mid + 1top = mid - 1TFFFTTend10-4Selection SortSelectionSorti = size - 1; i >= 1; --ilarge = a[0]index = 0j = 1; j <= i; ++j ifa[j] > largelarge = a[j]index = jTFa[index] = a[i]a[i] = largeend10-5InsertionSorti = size - 1; i >= 1; --iindex = ij = 0; j <= i-1; ++j ifa[j] > a[index]index = jTFendtemp = a[i]a[i] = a[index]a[index] = temp10-6Name(s) __________________________________________Text File/Bubble Sort LabEnter the following in a file called mydata.datAl Average2.5Sue Smart3.98Phil Physics3.75Lucy Lost1.5Wally Workshard3.02Ruth Returningwoman4.0Write a program containing three functions called LoadArrays, BubbleSort, andPrintArrays. LoadArrays will open the above file and load the arrays declared in themain (an array of strings to hold the names and an array of floats to hold the grade pointaverages). The arrays will be sent to function BubbleSort and you will use the bubblesort flowchart done in class to sort from the highest grace point average to the lowest.Don't forget to move the names too. The PrintArrays function outputs the contents of thetwo arrays in table format.main- declare necessary variables- call LoadArrays- call PrintArrays- call BubbleSort- call PrintArraysend main10-7Name ____________________________________________________Date _____________Lab ExerciseCreate the following array:int intArray[8] = {4, 1, 7, 12, 8, 13, 9, 21};Implement the sequential search as a void function and as a value returning function. Test bothversions by sending a key that is in the list and a key that is not. Think carefully about theparameters and local declarations (if any) for each


View Full Document

Saddleback CS 1B - Searching & Sorting

Download Searching & Sorting
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Searching & Sorting and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Searching & Sorting 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?