Getting Started with TRANSACT (32247-90007)

110 Chapter6
Data Structures
The above program performs a bubble sort of valid part-numbers. You will never want to
do this, since it is much easier to let Transact do the sort for you via the
SORT=(part-number) option, but it does illustrate the dynamics of Transact's data
structures.
Lines 20 to 28 serially read the master set that contains part-numbers and dynamically
adds each to the program data storage. Line 22 reserves an additional 8 bytes of storage
each time it is executed.
Lines 29 to 31 and 49 to 68 perform the bubble sort. The idea of a bubble sort is that for
each pass over the data, the lowest key item is floated to the top. Also, the second pass over
the data knows that the first pass found the lowest value item, so it only has to look at all
data except the one at the top (which is already lowest).
No-of-parts is the count of the total number of items. Parts-this-pass is the total number of
items that need to be scanned during this pass of the bubble sort. Count is just a counter
that is reinitialized and reused as an index through the data storage throughout the
program.
Line 30 sets things up for the first pass of the sort. Line 67 sets things up for the next pass
of the bubble sort after the previous pass has been completed.
Lines 31 and 32 control the passes of the sort.
Line 51 makes use of a marker to set the data storage pointer to the start of the part
numbers. Lines 53 to 66 increment through the part numbers, comparing one entry to the
next. The integral part of this loop is lines 56, 57, and 65. Lines 56 and 57 name or remap
the next two parts to be compared. Line 65 backs the program up one item so that the next
loop will compare the winner of the last compare with the next item.
Lines 58 to 64 perform the compare of the next two parts and when completed, the lowest
value part-number has been floated up. It is then compared to the next item during the
next loop.
After the bubble sort is completed, lines 33 to 39 remap the data storage to just contain the
name part-number. This needs to be done because the bubble sort routine kept calling
items from-part and to-part.
Lines 40 to 46 start at the top and print out the value of each part-number in ascending
order.