CS 106A Lecture Notes - Lecture 9: Bubble Sort, Selection Sort, Linear Search

30 views3 pages

Document Summary

Key = value you are looking for a. iii. For(int i = 0; i < array. length; i ++){ If(key == array[i]) return i; return -1; a. iii. 2. a. iii. 3. a. iii. 4. a. iii. 5. a. iii. 6. If it does exist, returns index value of first time the value appears. Only works if already sorted from smallest to largest or a. iv. 2. alphabetical or some other system. ] else{ rh = mid 1; lh = mid + 1; return -1; a. iv. 3. a. iv. 4. lh = left hand rh = right hand a. iv. 4. a. left and right hand keep approaching each other until meet a. iv. 5. Compare components of grect ( like height, width, coordinates: sorting data, selection sort a. i. Find smallest number in left over set, put right after first. Private int findsmallest(int[] array, int p1, int p2) For(int i = p1 + 1; i < p2; i ++){ //check if number is smaller than smallest so far return spos; a. iii. //swap smallest element with initial position: bubble sort b. i.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents