CS 1355
Introduction to Programming in C
Thursday 2006.10.24 (Week 7)
Lecture notes (at http://r638-2.cs.nthu.edu.tw/C/notes/14.txt)
Chapter 6: Arrays (continued)
- search: linear vs binary search
- multiple-subscripted arrays
What is "search"
- look up a data record using a "key"
- what is a key?
example: name, student ID, product number etc.
- input: key
- output: data record, or "not found"
Linear Search:
- go through array from beginning,
as soon as we find a match, return.
Example:
#include
#define SIZE 14
int key[ ] = {
1101, 1102, 1103, 1104, 1107,
1108, 1109, 1110, 1201, 1203,
1207, 1210, 1213, 1215
};
char* company[ ] = {
"