1. public class DMSList {
    2. private IntNode head;
    3. DMSList() {
    4. this.head = new IntNode(-1000, new LastIntNode());
    5. }
    6. public class IntNode {
    7. IntNode next;
    8. int val;
    9. IntNode(int val, IntNode next) {
    10. this.val = val;
    11. this.next = next;
    12. }
    13. public int max() {
    14. return Math.max(val, next.max());
    15. }
    16. }
    17. public class LastIntNode extends IntNode {
    18. LastIntNode() {
    19. super(0, null);
    20. }
    21. @Override
    22. public int max() {
    23. return 0;
    24. }
    25. }
    26. public int max() {
    27. return head.next.max();
    28. }
    29. public void insertFront(int x) {
    30. head.next = new IntNode(x, head.next);
    31. }
    32. public static void main(String[] args) {
    33. DMSList a = new DMSList();
    34. a.insertFront(0);
    35. a.insertFront(2);
    36. a.insertFront(7);
    37. a.insertFront(5);
    38. System.out.println(a.max());
    39. }
    40. }