public class DMSList {
private IntNode head;
DMSList() {
this.head = new IntNode(-1000, new LastIntNode());
}
public class IntNode {
IntNode next;
int val;
IntNode(int val, IntNode next) {
this.val = val;
this.next = next;
}
public int max() {
return Math.max(val, next.max());
}
}
public class LastIntNode extends IntNode {
LastIntNode() {
super(0, null);
}
@Override
public int max() {
return 0;
}
}
public int max() {
return head.next.max();
}
public void insertFront(int x) {
head.next = new IntNode(x, head.next);
}
public static void main(String[] args) {
DMSList a = new DMSList();
a.insertFront(0);
a.insertFront(2);
a.insertFront(7);
a.insertFront(5);
System.out.println(a.max());
}
}