Large number structure, tag can be put (sign)
Wei can be put in length
Num puts one digit in the value
Next put down one (higher one)
public class bignum{
Boolean tag = true;
int num = 0;
int wei= 1;
Bignum Next;
}
public class Shuju {
public static void Main (string[] args) {
TODO auto-generated Method Stub
Bignum a = new Bignum ();
Getdemo (a);
System.out.println ("---------a------------------");
Out (a);
Bignum B = new Bignum ();
Getdemo (b);
System.out.println ("-----------b---------------");
Out (b);
Bignum Bignum = Add (a, b);
System.out.println ("-----------------------------");
Out (Bignum);
}
private static void Out (Bignum bignum) {
for (Bignum t = bignum.next;t! = null;) {
System.out.print (T.num);
t = T.next;
}
}
Static Bignum Add (Bignum A, bignum b) {
Bignum result = new Bignum ();
Bignum temp = result;
for (;(a! = NULL | | b!= null);) {
if (a = = null) {
ADD1 (temp, 0, b.num);
}
if (b = = null) {
ADD1 (temp, 0, a.num);
}else{
ADD1 (temp, a.num, b.num);
A= A.next;
B= B.next;
}
if (Temp.next = = null) {
Temp.next = new Bignum ();
}
temp = Temp.next;
}
return result;
}
public static void Add1 (Bignum A, int n, int m) {
if (A.next = = null) {
A.next = new Bignum ();
}
int tem = 0;
TEM = n + M + a.num;
A.num = tem% 10;
if (Tem/10 >0) {
ADD1 (A.next, 1, a.next.num);
}
}
Interview is not necessarily whether you understand, but also to see if the person interviewed you understand you, because the general algorithm is not readily available on the paper, after all, can not be returned is not it,
Infinitely large number added-, can be conveniently changed to subtract, multiply