Bear Bibeault wrote:Welcome to the Ranch.
Two things:You didn't state your motivation for re-inenting the wheel. Without a reason, the best advice is to not re-invent the wheel. Without posted code (please UseCodeTags), only guesses are possible.
the arrays can come in different sizes
and the numbers are positive and negative.
Ulf Dittmer wrote:
the arrays can come in different sizes
Is that a requirement? I've worked with MPI (multi precision integer) libraries that fix the number of digits - that reduces complexity and increases speed considerably.
Ulf Dittmer wrote:
and the numbers are positive and negative.
Since you're using decimal arithmetic, it's relatively easy to get around this. Create a temporary array where each index holds the sum for the two digits to add at that index. For each of the two digits you're using its negative if the respective number had a minus sign. Then you "normalize" the result by moving all digits into the 0-9 range -starting from the last digit- and incrementing/decrementing the next higher digit depending on whether you had to add or subtract 10 from the lower digit. This approach makes implementing subtraction trivial once you've implemented addition.
Junilu Lacar wrote:I take it that you'd like to do something like this:
If the assignment is meant to help you better understand algorithms, what's your algorithm for addition that you're supposed to better understand by trying to implement it? Or are you supposed to come up with your own algorithm?
Junilu Lacar wrote:
One thing I can say right off the bat is that your choice of variables names doesn't help in making your code readable. Readable code is easier to understand and it goes a long way to make your thought process flow better. Bad names like aIILength and bIILength are like speed bumps in your head when you read them. Go ahead, try reading your code OUT LOUD and see if what you hear yourself saying makes a lot of sense.
When a class is designed like this, it's best to think in terms of this and the other instance. For example, the "standard" way to implement you own equals method looks something like this:
See how the choice of names makes reading the code OUT LOUD much easier and almost conversational?
devin kinh wrote:I'll make sure to make more sensible variable names if I plan on getting help for my code.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |