home *** CD-ROM | disk | FTP | other *** search
- PROCshell_QuickSort()
- Params =>
- str comparison function
- str swap function
- bool ascending flag, non 0 for ascending
- sort, 0 for descending sort
- int minimum element number to sort
- int maximum element number to sort
-
- The QuickSort routine uses a fast sorting technique
- which is capable of sorting any type of data. An
- example of the speed is that 1000 random integers
- can be sorted in around 15 seconds on an ARM3
- machine.
-
- Comparision FN (QuickSort)
- Params =>
- int first element nr
- int second element nr
-
- <=
- bool TRUE if value of first element
- is less than the second,
- otherwise FALSE
-
- This function returns TRUE or FALSE depending
- on the outcome of the comparison. Exactly what
- is compared is up to you!
-
- The function name must start with a '_'
- character if the program is to be compressed.
-
- Swap FN (QuickSort)
- Params =>
- int first element nr
- int second element nr
-
- <=
- int junk (ignore)
-
- This function swaps element 1 with element
- 2.
-
- The function name must start with a '_'
- character if the program is to be compressed.
-
- Example code (QuickSort)
- Assume a 100 element string array name$(), each element
- containing a list of names which must be sorted into
- alphabetic order. This can be achieved with:
-
- REM Rest of code....
- PROCshell_QuickSort("_QS_comp","_QS_swap",1,0,100)
- REM More code..
-
- DEF FN_QS_comp(el1%,el2%)
- IF VAL(name$(el1%)) < VAL(name$(el2%)) THEN = TRUE ELSE = FALSE
- :
- DEF FN_QS_swap(el1%,el2%)
- LOCAL temp$
- temp$ = name$(el1%)
- name$(el1%) = name$(el2%)
- name$(el2%) = temp$
- =0
-
- The complexity of FN_QS_comp and FN_QS_swap is completely up to
- you (wildcards could be allowed for example). By this means any
- set of data can be sorted.
-
- --------------------------------------------------------
-
- FNshell_BinarySearch()
- Params =>
- str search term
- str get term function
- str comparison function
- int minimum element number
- int maximum element number
-
- <=
- int element number of first match
- found (first element is 1) or
- -1 if match not found
-
- The Binary Search technique is a powerful way of
- quickly searching a set of sorted data. The way in
- which it has been implemented for EvntShell makes
- it even more useful in that any set of data can be
- searched by the same routine.
-
- The key to this are the two routines called during
- the search to get an element of data and to compare
- one element to another.
-
- Search term (BinarySearch)
- The search term is the string which will be searched
- for during the binary search. Note that a string must
- be passed to the search routine, numbers must be
- converted first using STR$.
-
- Get Term FN (BinarySearch)
- Params =>
- int element number to fetch
-
- <=
- str value of element number
-
- This function returns a string representing
- the value of the specified element.
-
- The function name must start with a '_'
- character if the program is to be compressed.
-
- Comparision FN (BinarySearch)
- Params =>
- str term 1
- str term 2
-
- <=
- bool TRUE if term 1 is less than
- term 2, otherwise FALSE
-
- This function returns TRUE or FALSE depending
- on the outcome of the comparison. Exactly what
- is compared is up to you!
-
- The function name must start with a '_'
- character if the program is to be compressed.
-
- The Binary Search Technique
- Given a set of sorted data, a check is first made halfway
- through the list. If the searched for data is 'greater than'
- this value then the next check is made half way between the
- first point and the end of the list, otherwise the next check
- is made half way between the first check and the start of the
- list.
-
- This continues (eliminating half the remaining data with each
- check) until the data is found, or the list can contain no
- more matches.
-
- By this means very large amounts of data can be searched very
- quickly indeed.
-
- Example code (BinarySearch)
- Assume a 100 element string array array$(), each element
- containing a list of names sorted into alphabetic order.
- The search can be carried out with:
-
- result%=FNshell_BinarySearch("Fred","_GetTerm","_Comp",0,99)
- REM rest of code....
-
- DEF FN_GetTerm(nr%)
- =array$(nr%)
- :
- DEF FN_Comp(term1$,term2$)
- IF term1$ < term2$ THEN = TRUE ELSE =FALSE
-
- result% contains -1 if 'Fred' is not present in array$, or
- the element number if it is. The complexity of FN_GetTerm
- and FN_Comp is completely up to you (wildcards could be
- allowed for example). By this means any set of sorted data
- can be searched - simply define the 'get term' and 'comparision'
- functions to suit.