Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. public class BigInteger {
  2. DigitNode front;
  3. private static class DigitNode {
  4. int digit;
  5. DigitNode next;
  6. public DigitNode(int digit) {
  7. this.digit = digit;
  8. this.next = null;
  9. }
  10. public DigitNode(int digit, DigitNode next) {
  11. this.digit = digit;
  12. this.next = next;
  13. }
  14. public String toString(){
  15. String out = "";
  16. DigitNode cur = this;
  17. while(cur != null) {
  18. out += "(" + cur.digit + ") -> ";
  19. cur = cur.next;
  20. }
  21. return out;
  22. }
  23. }
  24. public BigInteger append(int d){
  25. DigitNode cur = this.front;
  26. while(cur.next != null) {
  27. cur = cur.next;
  28. }
  29. cur.next = new DigitNode(d);
  30. return this;
  31. }
  32. public String toString(){
  33. return this.front.toString();
  34. }
  35. public static void main(String[] args) {
  36. BigInteger b = new BigInteger();
  37. b.front = new DigitNode(1, new DigitNode(2, new DigitNode(3, new DigitNode(4, new DigitNode(5)))));
  38. System.out.println(b);
  39. System.out.println(b.append(6));
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement