When you pass an array you pass its memory addresss therefore by reference void

When you pass an array you pass its memory addresss

This preview shows page 3 - 4 out of 4 pages.

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)
Image of page 3
{ 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
Image of page 4

You've reached the end of your free preview.

Want to read all 4 pages?

  • Fall '13
  • Boykov

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture