package com.smuralee.collection;

public class LinkedList {

    private LinkedNode head;

    public void append(int data) {
        if (head == null) {
            head = new LinkedNode(data);
            return;
        }

        LinkedNode current = head;
        while (current.next != null) {
            current = current.next;
        }
        current.next = new LinkedNode(data);
    }

    public void prepend(int data) {
        LinkedNode newHead = new LinkedNode(data);
        newHead.next = head;
        head = newHead;
    }

    public void deleteWithValue(int data) {
        if(head == null) return;
        if(head.data == data){
            head = head.next;
            return;
        }

        LinkedNode current = head;
        while(current.next != null){
            if(current.next.data == data){
                current.next = current.next.next;
                return;
            }
            current = current.next;
        }
    }

}

class LinkedNode {
    LinkedNode next;
    int data;

    LinkedNode(int data) {
        this.data = data;
    }
}
