/*******************************************************************
* Author: Isai Damier
* Title: LargeInteger.java
* Project: geekviewpoint
* Package: datastructure
*
* Description: Normally modern computers cannot handle very large
* numbers. So the task here is to create a datastructure that
* can handle numbers of perhaps infinite size. And to prove that
* the datastructure works, included are arithmetic operators.
*
* Naturally the numbers are represented as Strings. And to
* perform addition and subtraction, stacks are used as the media.
* Finally, as any trusty calculator, this datastructure returns
* erroneous values for erroneous inputs and correct values for
* correct inputs. This is to say, if an input string does not
* represent a valid decimal integer, then the output string
* will be bogus.
******************************************************************/
import java.util.Stack;
public class LargeInteger {
private String number;
public LargeInteger(String number) {
this.number = number;
}//constructor
/***************************************************************
* Function: toIntegerStack
* Inputs: @param n
* Output: Stack<Integer>
*
* Description: This auxiliary function converts a String into a
* stack of integers. The function makes no checks for erroneous
* values. The user will get what the user asks for.
*
**************************************************************/
private Stack<Integer> toIntegerStack(String n) {
Stack<Integer> stack = new Stack<Integer>();
for (char c : n.toCharArray()) {
//stack.push(c - 48);//ASCII
stack.push(Integer.parseInt(c+""));
}
return stack;
}
}