Chapter 10 |
|
Home Chapter 1 Chapter 2 Chapter 3 Chapter 4 Chapter 5 Chapter 6 Chapter 7 Chapter 8 Chapter 9 Chapter 10 Chapter 11 Chapter 12 Chapter 13 Chapter 14 Chapter 15 Table of Contents |
Some Fundamental algorithmsThe simple exchange sort is about three lines long: if the array to sort is A(), containing MaxItems itemss, the following lines will sor the array:
If a (Front) > a (Back) Then
The bubble sort works by comparing adjacent items in the list and swapping out-of-order entries. An advantage of the bubble sort is that it will stop when the items are in order. The comb sort is a modification of the bubble sort. Instead of comparing adjacent elements, it compares elements that are a certain gap apart. The gap between the compared elements is reduced until finally, the comb sort becomes the bubble sort. It is a very fast sort. This Open statement:
Opens the file c:\temp\cdfile.dat as a random access file for readonly access as file number 1. The Put statement writes information to a random access file:
The Get statement writes information from a random access file:
The EOF() function is True when the program tries to get from a file that is empty (because all the data has been read). The On error Go To "label" statement shifts program flow to an error-handling routine when a run-time error occurs. A linear search checks every item of an array looking for the occurrence of a string or value. A simple loop is used to cycle through the items of the array. A binary search tests the middle element of a sorted array. If the search item is the middle element, the search is over. If the itme sought is less than the middle element, search the first half of the lsit. If the item is greater than the middle element, search the last half of the list. The Left$() function:
takes the first number of characters from the string and returns the result as a string. |