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;
    }
}

 

相关文章:

  • 2021-08-02
  • 2021-10-30
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-16
  • 2021-04-22
猜你喜欢
  • 2022-12-23
  • 2021-09-22
  • 2021-09-18
  • 2022-12-23
  • 2021-05-19
  • 2021-09-12
  • 2022-12-23
相关资源
相似解决方案