I’m writing a program that allows a user to perform arithmetic operations with big numbers, that are constructed using doubly linked lists. So far I’ve made an addition function, but now I’m trying to make one for multiplication and I can’t really come up with something good. I was thinking of doing this:
Suppose there are 2 numbers, 1000 and 2000|0000 (the | represents the break between the different nodes that the number is composed of). If you multiply the numbers you will get 200|0000|0000. I could make a function that first multiplies 2 nodes and then divides it into smaller nodes. After that it would multiply the next nodes, check the size of the last node and, if there’s space left, add a part to to that node and put the remains in the next one. However, what if one number is smaller than the other one? Then you would multiply it with an undefined number.. Does this method have any “future”? Or should I look for another one (I did some research but didn’t find anything of use so far)
If performance is not important to you, you may user the ‘highschool method’. First implement a method that multiplies a number by a digit, then start multiplying one of the numbers by the digits ooh the other(also adding an offset to each consequent result) and then add these numbers. Something like:
Implementing this with linked lists should not be too difficult.