Make your own free website on

Chapter 10


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 algorithms

The 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:

    For Front = 1 To maxItems -1
      For Back = Front + 1 To maxItems
      If a (Front) > a (Back) Then
        ' swap the items
      Next Back
    Next Front

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:

    Open "c:\temp\cdfile.dat" For Random Access Read As #1

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:

    Put #<file number>, <record number>, <variable name>

The Get statement writes information from a random access file:

    Get #<file number>, <record number>, <variable name>

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:

    Left$( string, number of characters)

takes the first number of characters from the string and returns the result as a string.