Skip to content

Instantly share code, notes, and snippets.

@khayyamsaleem
Created September 23, 2019 00:58
Show Gist options
  • Save khayyamsaleem/b164e1eb683f6c02184ab6587f1da13b to your computer and use it in GitHub Desktop.
Save khayyamsaleem/b164e1eb683f6c02184ab6587f1da13b 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 DigitNode createBackwards(String num, DigitNode last) {
if (num.length() == 0) {
return last;
} else {
return createBackwards(num.substring(1), new DigitNode(Character.getNumericValue(num.charAt(0)), last));
}
}
public BigInteger(String input) {
this.front = this.createBackwards(input.substring(1), new DigitNode(Character.getNumericValue(input.charAt(0))));
}
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