Accounting Principles V11

Clive W. Humphris

DATA STRUCTURES: Data Sorting.  


A number of methods are used in the process of sorting data. Here we introduce one such technique, the 'bubble sort' where the sorted values move to the top or bottom of the sorted array, depending on the ascending or descending selection.

The time taken to complete the sort depends on how the original data is arranged and the number of array interchanges to be made. The data to be sorted could originate from a list of data items (these could be names) in a disk file where to speed up the process it's copied into an array. An array is a group of RAM locations that the central processor operates on. Once sorted the data can then be copied back to the original file.

The process is as follows. Compare each consecutive pair of data items, if the value of position(n) in the array is greater or less than the position(n + 1), (depending on the ascending or descending selection) then exchange that pair. Repeat for the next pair and so on, looping back to the beginning until the sort is completed.

It's not possible to show all the intermediate sorting as the number of exchanges increases significantly for larger numbers of items in the array. If you follow through the first few exchanges you will quickly get a feel of how it works.


Table of contents

previous page start next page