Information Technology Reference
In-Depth Information
write
of the record, the
new-status
will have a value of something other than 0. We check this field to make sure that the
write didn't have a problem, which it really shouldn't. However, by doing a check on this
status field, if a problem does occur, we have a message to tell us that somehow there was
a problem. If we omitted the check and had an abend, someone would have to research
the results. By our process we know right away that we had a problem, saving time and
frustration.
With the read of the input file and the load of the array, we can now concentrate
on the sort. The sort here is referred to as a bubble sort. Just as bubbles float upward, we
shall bring the smallest element to the top and the largest will wind up at the bottom. In
this case, we'll look at the zip code and wind up with the smallest zip code at the top and
the largest zip code at the bottom. All the zip codes will be sorted the way we expect
them to be. For sorting on this field, we'll start with the first one and compare it to the
second. For example, if the first zip code is the same or less than the second, we'll do
nothing. Had it been reversed, we would have swapped the entire first record of data with
the data of the second. Note that we are not swapping only zip codes. In either case, the
record with the smallest zip code will now be in the first position in the table. We will
now repeat the process comparing the zip codes of the first record with the third one.
After this compare and swap - if necessary - the record corresponding to the smaller zip
code will be in the first position of the table.
We now need to repeat this compare process using the first and fourth records,
then the first and the fifth ones and so on until our last compare will be between the first
record's zip code and the last record's zip code. This checking is occurring within our
array. When we finish this first step of the process, we will without any doubt have the
record with the smallest zip code in the first position of the array.
We'll now go on and repeat the same process but this time we will start with the
second record and the third - comparing zip codes - then the second and the fourth and
so on just as before. Whenever we have to, we will swap rows of the array just as we did
earlier - actually swapping records. When we finish this pass and wind up comparing the
second zip code to the last one, we will have the record with the smallest zip code in the
first position of the array and then the record with next larger one in the second position
of the table.
You can probably guess what the next step will be. We will proceed with the third
record, then the fourth one and so on until we start with the second last record and
compare its zip code to the zip code of the last record, and we shall be done. At this point
our array is completely sorted from smallest zip code to the largest. There probably will
be two records with the same zip code, but in our case, that won't matter. There is just
one word of caution. In order to do a swap of two lines of the array, we can't just move
the first to the second and then the second to the first. If we did that, we would have lost
the second line. We will need a temporary place for either line and then three moves will
be required. One way would be to move the first line to the temporary line, the second to
Search WWH ::




Custom Search