Infinitely large number added-, can be conveniently changed to subtract, multiply

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.