Sequential lookups can be from the front to the back, or from the back to the front. Both of these can be
(1) The most basic order lookup
int Seqsearch (seqlist l,keytype k)
{
i = l.length;
while (I >= 1 && l.r[i].key! = k)
i--;
if (i > = 1)
return i;
return 0;
}
(2) To optimize the order lookup, is to add a listener, the above find the way time mainly consumes the two conditions of the while loop judgment. In fact, we will find that I >= 1, this judgment can be improved. If you add a lookout, put your keywords in r[0] so you don't have to Judge i>= 1.
int Seqsearch (seqlist l,keytype k)
{
i = l.length;
L.r[i].key = k;
while (l.r[i].key! = k)
i--;
return i;
}
There are two kinds of results returned
A. i > 0 Find success
B. i = 0 Lookup failed
The comparison of three kinds of search methods with the linear table
Order Lookup binary Find index Lookup
The structure of the table is orderly, orderly and orderly disorder
Table storage order chain sequential chain order
ASL (average lookup length) maximum minimum medium