• + 0 comments

    Using C

    Node* insert(Node *head,int data)
    {
        //Complete this function
        Node * tmp = head;
        Node *n = (Node*)malloc(sizeof(Node));  
        n->data = data;
        n->next = NULL;
        
        if(NULL == head){
            head= n;
        }else{
            if(tmp->next == NULL){
                head->next=n;
            }else{
                while(tmp->next != NULL){
                    tmp= tmp->next;
                    if(tmp->next == NULL){
                        tmp->next = n;
                        break;
                    }
                }
            }
        }
        
        return head;
    }