我应该使用什么数据结构来创建我自己的“BigInteger”类? [英] What data-structure should I use to create my own "BigInteger" class?
问题描述
作为一个可选的赋值,我正在考虑编写自己的BigInteger类的实现,其中我将提供我自己的加法,减法,乘法等方法。
As an optional assignment, I'm thinking about writing my own implementation of the BigInteger class, where I will provide my own methods for addition, subtraction, multiplication, etc.
这将是任意长整数,甚至数百位数。
This will be for arbitrarily long integer numbers, even hundreds of digits long.
在对这些数字进行数学运算时,你认为最好的数据结构是代表我的BigInteger吗?
While doing the math on these numbers, digit by digit isn't hard, what do you think the best datastructure would be to represent my "BigInteger"?
一开始我考虑使用一个数组,但是我想我仍然可能溢出出阵列槽)在大的加或乘之后。这是一个很好的情况下使用链表,因为我可以处理数字与O(1)时间复杂性?
At first I was considering using an Array but then I was thinking I could still potentially overflow (run out of array slots) after a large add or multiplication. Would this be a good case to use a linked list, since I can tack on digits with O(1) time complexity?
是否有一些其他数据结构比链表更适合?如果我的数据结构所保持的类型是我可用的最小可能的整数类型?
Is there some other data-structure that would be even better suited than a linked list? Should the type that my data-structure holds be the smallest possible integer type I have available to me?
此外,我应该小心如何存储我的进位变量?