java-fundamentals-exercises icon indicating copy to clipboard operation
java-fundamentals-exercises copied to clipboard

2-2-4-linked-list, contains()'s tests accept this wrong solution

Open obaibula opened this issue 2 years ago • 0 comments

The corrupted code:

@Override
    public boolean contains(T element) {
        requireNonNull(element);
        Node<T> current = head;

        if(!isEmpty()){
            while (current.next != null){
                if (current.element.equals(element)){
                    return true;
                }
                current = current.next;
            }
        }

        return false;
    }

It would be great to check in tests for the presence of the last element in the list.

obaibula avatar Apr 10 '23 06:04 obaibula