• + 0 comments

    C Approach

    For Beginners

    Node* insert(Node *head,int data) {

    struct Node* new_node = (struct Node*) malloc(sizeof(struct Node));
    Node *ptr = head ;
    new_node->data = data;
    new_node->next = NULL;
    if(head==NULL){
        return new_node;
    }
    while(ptr->next!=NULL){
        ptr = ptr->next;
    }
    ptr->next = new_node;
    return head;
    

    }