public class Node {
    public String data;
    public Node next;

    public Node(String data, Node next) {
        this.data = data;
        this.next = next;
    }
    public Node(String data) {
        this.data = data;
    }
}

public class LList {
    Node head;
    Node tail;
    Node listItemNode;

    public LList() {
        head = new Node(null, null);
        tail = head;
        System.out.println("LList Constructor");
    }

    public void add(String value) {
        System.out.println("LList Add");
        if(tail == head) {
            System.out.println("LList tail == head Empty List at this point");
            head.data = value;
            tail = new Node(null);
            head.next = tail;

        } else if(tail.data == null) {
            System.out.println("LList has a head but empty tail data");
            tail.data = value;
            tail.next = null;
        }
        else {
            System.out.println("LList tail != head List has in place Head and Tail data values");
            listItemNode = new Node(value, null);
            tail.next = listItemNode;
            tail = listItemNode;
        }
    }

    public void insert(int insertPosition, Node newNode) {
        Node p = head;
        int i = 0;
        // Move the node to the insertion point
        while(p.next != null && i < insertPosition -1) {
            p = p.next;
            i++;
        }
        newNode.next = p.next; //
        p.next = newNode;
    }

    public void delete(int removePosition) {
        Node p = head;
        int i = 0;
        //Move the node to the previous node position that is to be deleted
        while(p.next != null && i < removePosition - 1) {
            p = p.next;
            i++;
        }
        Node temp = p.next;
        p.next = p.next.next;
        temp.next = null;
    }

    public void print() {
        System.out.println("LList Print List");
        Node p = head;
        System.out.print("Head->");
        while(p != null) {
            System.out.print(p.data + "->");
            p = p.next;
        }
        System.out.println("Tail.");
    }
}

public class SingleLinkedListAll {
    public static void main(String[] args) {
        LList linkedList = new LList();

        linkedList.add("Carmarthen");
        linkedList.add("Llanelli");
        linkedList.add("Swansea");
        linkedList.add("Neath");
        linkedList.add("Port Talbot");
        linkedList.add("Bridgend");
        linkedList.add("Cardiff");
        linkedList.add("Newport");
        linkedList.add("Bristol");
        linkedList.add("Swindon");
        linkedList.add("Reading");
        linkedList.add("London Paddington");
        linkedList.print();

        System.out.println("Insert a new node Didcot Parkway at index = 10:");
        linkedList.insert(10, new Node("Didcot Parkway", null));
        linkedList.print();

        System.out.println("Delete the node Didcot Parkway at index = 10:");
        linkedList.delete(10);
        linkedList.print();
    }
}