为什么我的方法 removeDuplicates() 不返回没有重复项的链表?

Why isn't my method removeDuplicates() returning a Linked List without the duplicates?

当我尝试实现一种删除重复项的方法时,它 returns 仍然包含重复项的链表。我不确定这是变量赋值的问题还是潜在的 show()我创建的方法。

https://www.dropbox.com/s/2cjj4nb4v8i5fg9/RemoveDuplicates.zip?dl=0

public class LinkedList {
    LinkedListNode head;

    //generating add method to 
    public void add(int data) {
        LinkedListNode newNode = new LinkedListNode();
        newNode.data = data;
        newNode.next = null;

        if (head == null) {
            head = newNode;
        }
        else {
            LinkedListNode current = head;
            while(current.next != null) {
                current = current.next;
            }
            current.next = newNode;
        }
    }
    public void show() {
        LinkedListNode newNode = head;

        while(newNode.next != null) {
            System.out.println(newNode.data);
            newNode = newNode.next;
        }
        System.out.println(newNode.data);

    }
}

public class Test {


    public static void main(String[] args) {
        LinkedListNode head = new LinkedListNode();

        //12 and 5 are duplicates
        LinkedList list = new LinkedList();
        list.add(5);
        list.add(45);
        list.add(12);
        list.add(12);
        list.add(5);
        list.add(33);
        list.add(12);
        list.add(45);

        list.show();

        removeDuplicates(head);

        list.show();
    }

    public static void removeDuplicates(LinkedListNode head) {

        LinkedListNode current = head;
        LinkedListNode runner = null;


        while (current != null) {
            runner = current;
            while (runner.next != null) {
                if (runner.next.data == current.data) {
                    runner.next = runner.next.next;
                }
                else {
                    runner = runner.next;
                }

            }
            current = current.next;

        }

    }
}

main 方法中的 head 与链表中的 head 不同。

您的 main 方法中的 head 始终为空,您根本没有修改 list