Cryptography Reference
In-Depth Information
(c)
FIGURE 2.2
(continued)
(d)
(e)
2.2
COMPARISON METHODS
We should write methods that allow us to compare Int objects; that is, methods to tell us when
they are equal, and if one is less than another. To determine whether Int
x
is less than Int
y
,
for example, we could do the following:
• If
x
and
y
are of different signs, the negative one is smaller. Otherwise, continue with the
next step.
• If the arrays representing
are different lengths, and if both are negative, then the
larger array is the smaller number. Otherwise the smaller array represents the lesser of the
two Ints. If both arrays are the same length, continue with the next step.
• Proceed down the array until you find unequal digits. If both
x
and
y
are negative, the array
containing the smaller digit is the largest. Otherwise, the array containing the larger digit
represents the larger integer. If you find no unequal digits, neither integer is larger.
x
and
y
Search WWH ::




Custom Search