Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement