class NodeList{ private Node head; private Node tail; void print(){ Node node = head; while (node != null){ System.out.print(node.date+","); node = node.next; } System.out.println(); } private void add(int val){ Node newNode = new Node(val); if(head == null){ head = newNode; tail = newNode; }else { tail.next = newNode; tail = newNode; } } private void rever(){ tail = head; Node pre = null; Node temp = null; Node p = head; while (p != null){ temp = p.next; p.next = pre; pre = p; p = temp; } head = pre; } public static void main(String[] args) { NodeList list = new NodeList(); list.add(1); list.add(2); list.add(3); list.rever(); list.print(); } } class Node{ public int date; public Node next; public Node(int date) { this.date = date; } }