Information Technology Reference
In-Depth Information
the first and finally the temporary line back to the second. In this way we will have
achieved the swap without losing any line.
Again, I can't emphasize enough that even though we are comparing zip codes,
our array consists of more data than just that field. We need to swap the entire line and
not just parts of it as would be done if we were to merely swap the zip codes. After all, if
we did that Chris Smith could wind up with Pat Jones' zip code and we don't want that.
With that in mind the lines
perform sort-array varying i-sub from 1 by 1 until i-sub = record-count - 1
sort-array: process-sw = 0
t-sub = i-sub
perform match-ssn until process-sw = 1
match-ssn: t-sub = t-sub + 1
if c-element ( i-sub )(86:5) > c-element ( t-sub )(86:5) then
hold-line = c-element ( i-sub )
c-element ( i-sub ) = c-element ( t-sub )
c-element ( t-sub ) = hold-line
end-if
if t-sub = record-count
process-sw = 1
end-if
will do just exactly what we need to do to sort the array. Recall that
record-count
represents the number of records in the table. The main perform will loop through varying
i-sub
from 1 until it is 1 less than the record count. Thus if we had 10 records, the
sort-table
procedure would represent 9 groups of compares, the first number against the remaining
9, then the second number against the remaining 8 and so on down the line. These groups
of compares will be done by the procedure
match-ssn .
Note that
t-sub
will be equal to
i-sub
to start when we get to this procedure but very soon it will be 1 larger, then 2 larger and
so on. The very first compare will then compare the first number to the second since
i-sub
will be 1 and
t-sub
will be 2. The lines
Search WWH ::




Custom Search