Insert a Node at the Tail of a Linked List

  • + 15 comments

    Node Insert(Node head,int data) { Node tmp = new Node(); tmp.data = data; tmp.next = null;

    if(head == null) {
        head = tmp;
        return head;
    } 
    
    Node current = head;
    while(current.next != null) {
        current = current.next;
    }
    current.next = tmp;
    return head;
    

    }