如何获取 length 和 isEmpty 方法作为 return 值以获取用于我的循环链表的方法?

How to get length and isEmpty methods as a return value to get method used for my Circular Linked List?

当我看到链表中从未使用过的两个方法时遇到了一个问题: 新更新!!!

public class CircularLinkedList {

    private ListNode last;
    private int length;

    private static class ListNode {
        private ListNode next;
        private final int data;

        public ListNode(int data) {
            this.data = data;
        }
    }

    public static void main(String[] args) {
        CircularLinkedList cll = new CircularLinkedList();
        CircularLinkedList insertBeg = new CircularLinkedList();
        CircularLinkedList insertEnd = new CircularLinkedList();

        System.out.println("creating a traverse list");
        cll.createCircularLinkedList();
        cll.display();
        System.out.println("Insert Starting Node");
        insertBeg.insertFirst(10);
        insertBeg.insertFirst(15);
        insertBeg.insertFirst(20);
        insertBeg.insertFirst(25);
        insertBeg.display();

        insertEnd.insertLast(25);
        insertEnd.insertLast(20);
        insertEnd.insertLast(15);
        insertEnd.insertLast(10);

        // I just need to print out the isEmpty amd length
        System.out.println(insertEnd.isEmpty());
        System.out.println(insertEnd.length());
        insertEnd.display();
    }

    public CircularLinkedList () {
        last = null;
        length = 0;
    }

    public void display() {
        if(last == null) {
            return;
        }

        ListNode first = last.next;
        while(first != last) {
            System.out.print(first.data + " --> ");
            first = first.next;
        }
        System.out.println(first.data);
    }

    public void insertFirst(int data) {
        ListNode temp = new ListNode(data);
        if (last == null) {
            last = temp;
        } else {
            temp.next = last.next;
        }
        last.next = temp;
        length++;
    }

    public void insertLast(int data) {
        ListNode temp = new ListNode(data);
        if (last == null) {
            last = temp;
            last.next = temp;
        } else {
            temp.next = last.next;
            last.next = temp;
            last = temp;
        }
        length++;
    }

    public int length () {
        ListNode temp = last.next;
        int count = length;
        while (temp != last) {
            count++;
            temp = temp.next;
        }
        return count;
    }

    public boolean isEmpty(){
        return length == 0;
    }

    public void createCircularLinkedList() {
        ListNode first = new ListNode(1);
        ListNode second = new ListNode(5);
        ListNode third = new ListNode(10);
        ListNode fourth = new ListNode(15);

        first.next = second;
        second.next = third;
        third.next = fourth;
        fourth.next = first;

        last = fourth;
    }
}

我试图通过使该方法失效来解决我的循环链表的这个问题。但是,我想测试并查看是否可以通过打印长度和 isEmpty 的值来使该方法正常工作。有没有办法在 IntelliJ 上解决这个问题?

Return 方法的值永远不会同时用于 length 和 isEmpty

这只是一个警告,一些其他代码正在调用该方法但忽略了结果。

解决方案是修复其他代码。