CPSC 170 Program 4: Big Integers
Due Friday, April 11 2008


The Java primitive type int uses a 32-bit two's complement representation, which allows it to represent values in the range -231 to 231-1 (-2147483648 to 2147483647). A programmer who needs to represent a larger number might use a long instead; with 64 bits this extends the range to -263 to 263-1 (-9223372036854775808 to 9223372036854775807). But what if the integers in a program can grow larger than that?   This may seem unlikely to you, but you experienenced numbers this big back in week five of CS120 when you were asked to represent your age in seconds.   Even more dramatic -  In week eight of cs120, we hit a ceiling with our factorial function 15!  (extending from an int to a long gets us up to 20!).  In situations like this it's useful to have a way to represent arbitrarily large integers. Their manipulation will not be nearly as efficient as that of regular integers, but at least it will be possible to work with them in some form.

Your assignment is to write two classes:

The BigInt ADT and Implementation

The BigIntADT interface is given below:
public interface BigIntADT
// Gives the number of digits in the BigInt
public int length();

// Returns a BigInt representing the sum of the
// current BigInt and int2
public BigIntADT add(BigIntADT int2);

// Returns a BigInt representing the product of the
// current BigInt and int2
public BigIntADT mult(BigIntADT int2);

// Returns a BigInt representing the the current BigInt
// raised to the int2 power
public BigIntADT power(BigIntADT int2);

// Returns a BigInt representing the factorial of int
public BigIntADT factorial(BigIntADT int)

// Returns true if the current BigInt is the same as
// int2, false otherwise
public boolean equals(BigIntADT int2);

// Returns a string representation of the current BigInt
public String toString();

// Returns an iterator that provides the digits of the current
// BigInt, one at a time.
public Iterator iterator();
You should write a LinkedBigInt class that uses a linked list to implement this interface. Some helpful advice:

The EvalBigInts Class

This is a program reads from a file containing multiple postfix expressions (delimited by a newline). Each postfix expression is itself space delimited. This program should represent the integers in the expression as BigInts, and uses stack evaluation to evaluate the expression. The expression may contain any non-negative integers but should contain only the operators +, *, ! and e (for exponent, so postfix 2 3 e = 23= 8).

Code for a stack evaluator is in the text and last week's lab; yours will be similar, but your use of bigints will require some modifications.