When you pass an array, you pass its memory address’s, therefore by reference
void printArray(int list[], int arraySize); //function definition
printArray(myList, 5);
//function call
Searching Arrays (Problem #1 with Arrays) aka Linear Search
Sequentially compares the key element with each element in the array list
Int linearSearch(const int list[], int ket, int arraySIze)

{
for (int i = 0; i < arraySize; i++)
{
if (key == list[i]
return i;
}
return -1;
}
Searching Arrays (Problem #1 with Arrays) aka Binary Search
Compares the key with the element in the middle of the array, then one of three
things can happen:
o
If the key is less than the middle element, you only need to search the first
half of the array
o
If the key is greater then the middle element, you only need to search the
last half of the array
o
If the key is equal to the middle, you found your value
The array needs to be sorted before using this search method
Selection Sort
Finds the smallest number in the list, and swaps it with the first element in the
array. Then takes the second smallest element and puts it in the second spot in the
array

You've reached the end of your free preview.
Want to read all 4 pages?
- Fall '13
- Boykov