Skip to content

Instantly share code, notes, and snippets.

@khayyamsaleem
Created September 23, 2019 00:41
Show Gist options
  • Save khayyamsaleem/69e0f0efa6e93aa3dd4633f036d5b45f to your computer and use it in GitHub Desktop.
Save khayyamsaleem/69e0f0efa6e93aa3dd4633f036d5b45f to your computer and use it in GitHub Desktop.
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 + ") -> ";
cur = cur.next;
}
return out;
}
}
public String toString() {
return this.front.toString();
}
public BigInteger(String input) {
this.front = new DigitNode(Character.getNumericValue(input.charAt(0)));
DigitNode cur = this.front;
for (int i = 1; i < input.length(); i++) {
cur.next = new DigitNode(Character.getNumericValue(input.charAt(i)));
cur = cur.next;
}
}
public static void main (String[] args) {
BigInteger b = new BigInteger("12345");
System.out.println(b);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment