searching_20ordered_20lists
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
searching_20ordered_20lists [2018/03/31 13:19] – external edit 127.0.0.1 | searching_20ordered_20lists [2024/01/05 00:21] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 2: | Line 2: | ||
//by Richard Russell, December 2006//\\ \\ The fastest way to search an //ordered// list is the **binary search**; you can find a description of how it works in the [[http:// | //by Richard Russell, December 2006//\\ \\ The fastest way to search an //ordered// list is the **binary search**; you can find a description of how it works in the [[http:// | ||
+ | <code bb4w> | ||
DEF FNwhere(A$(), | DEF FNwhere(A$(), | ||
LOCAL B%, H%, T% | LOCAL B%, H%, T% | ||
Line 13: | Line 14: | ||
UNTIL H%=0 | UNTIL H%=0 | ||
IF S$=A$(B%) THEN = B% ELSE = -1 | IF S$=A$(B%) THEN = B% ELSE = -1 | ||
+ | </ | ||
If the supplied string matches one of the elements in the array the function returns the index of the matching element. If there is no match the function returns -1.\\ \\ Note that the entire array must be pre-sorted into alphabetical sequence.\\ \\ **Important note:**\\ \\ It is important that the method you use to **sort** the array is compatible with the method you use to **search** the array, i.e. that they use the same //collation order//. Specifically, | If the supplied string matches one of the elements in the array the function returns the index of the matching element. If there is no match the function returns -1.\\ \\ Note that the entire array must be pre-sorted into alphabetical sequence.\\ \\ **Important note:**\\ \\ It is important that the method you use to **sort** the array is compatible with the method you use to **search** the array, i.e. that they use the same //collation order//. Specifically, | ||
+ | <code bb4w> | ||
DEF FNwhere(A$(), | DEF FNwhere(A$(), | ||
LOCAL B%, H%, R%, T% | LOCAL B%, H%, R%, T% | ||
Line 28: | Line 31: | ||
UNTIL H%=0 | UNTIL H%=0 | ||
IF S$=A$(B%) THEN = B% ELSE = -1 | IF S$=A$(B%) THEN = B% ELSE = -1 | ||
+ | </ | ||
\\ By changing the second parameter of **CompareString** from 0 to 1 a //case insensitive// | \\ By changing the second parameter of **CompareString** from 0 to 1 a //case insensitive// |
searching_20ordered_20lists.1522502379.txt.gz · Last modified: 2024/01/05 00:16 (external edit)