Skip to content

Instantly share code, notes, and snippets.

@khayyamsaleem
Created September 27, 2019 00:48
Show Gist options
  • Select an option

  • Save khayyamsaleem/3ccdd4ed09f24bd125ba72991eb041d8 to your computer and use it in GitHub Desktop.

Select an option

Save khayyamsaleem/3ccdd4ed09f24bd125ba72991eb041d8 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(){
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