Possible Duplicate:
What data-structure should I use to create my own “BigInteger” class?
Out of pure interest, I am trying to design a type that can hold an arbitrarily large integer. I want to support four basic operations [+, -, *, /]
and optimise for speed of those operations.
I was thinking about some sort of a doubly-linked list and a bit flag to indicate positive or negative value. But I am not really sure how to add, for example, to large numbers of different sizes. Shall I walk to the last element of both numbers and then return back (using the second reverse pointer to the previous element).
123456789 //one large number + 123 //another large number with different size
Providing I can have an arbitrarily large memory, what is the best data structure for this task?
I would appreciate a small hint and any comments on worst-case complexity of the arithmetic operations. Thanks!