Last active
September 22, 2019 21:53
-
-
Save khayyamsaleem/37fdd17ef7278c512b9578e759da73a7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BigInteger { | |
DigitNode front; | |
private static class DigitNode { | |
int digit; | |
DigitNode next; | |
public DigitNode(int digit) { | |
this.digit = digit; | |
this.next = null; | |
} | |
public DigitNode(int digit, DigitNode next) { | |
this.digit = digit; | |
this.next = next; | |
} | |
public String toString(){ | |
DigitNode cur = this; | |
String out = ""; | |
while (cur != null) { | |
out += "(" + cur.digit + ") -> "; | |
} | |
return out; | |
} | |
} | |
public String toString() { | |
return this.front.toString(); | |
} | |
public static void main (String[] args) { | |
BigInteger b = new BigInteger(); | |
b.front = new DigitNode(5); | |
b.front.next = new DigitNode(4); | |
b.front.next.next = new DigitNode(3); | |
b.front.next.next.next = new DigitNode(2); | |
b.front.next.next.next.next = new DigitNode(1); | |
System.out.println(b); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment