Insert a Node at the Tail of a Linked List

  • + 0 comments

    // cpp code SinglyLinkedListNode* insertNodeAtTail(SinglyLinkedListNode* head, int data) { //ll doestnt exist

        if(head==NULL){
            head= new SinglyLinkedListNode(data);
            return head;
        }
        //ll already exist
        else{
         SinglyLinkedListNode* temp=head;
         while(temp->next!=NULL){
            temp=temp->next;
         }
         temp->next=new SinglyLinkedListNode(data);
         return head;
        }
    

    }