Created
September 27, 2019 00:48
-
-
Save khayyamsaleem/3ccdd4ed09f24bd125ba72991eb041d8 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(){ | |
| String out = ""; | |
| DigitNode cur = this; | |
| while(cur != null) { | |
| out += "(" + cur.digit + ") -> "; | |
| cur = cur.next; | |
| } | |
| return out; | |
| } | |
| } | |
| public BigInteger append(int d){ | |
| DigitNode cur = this.front; | |
| while(cur.next != null) { | |
| cur = cur.next; | |
| } | |
| cur.next = new DigitNode(d); | |
| return this; | |
| } | |
| public String toString(){ | |
| return this.front.toString(); | |
| } | |
| public static void main(String[] args) { | |
| BigInteger b = new BigInteger(); | |
| b.front = new DigitNode(1, new DigitNode(2, new DigitNode(3, new DigitNode(4, new DigitNode(5))))); | |
| System.out.println(b); | |
| System.out.println(b.append(6)); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment