#include<stdio.h>
#include<stdlib.h>

struct Node{
    int data;
    struct Node* next;
};

struct Node* createNode(int a){
    struct Node* n=(struct Node *)malloc(sizeof(struct Node));
    n->data=a;
    n->next=NULL;
    return n;
}

void insertAtEnd(struct Node** head,int a){
    struct Node* newNode=createNode(a);
    if(*head==NULL){
        *head=newNode;
        return;
    }
    struct Node* temp=*head;
    while(temp->next!=NULL){
        temp=temp->next;
    }
    temp->next=newNode;
    
}

void insertAtK(struct Node** head,int a,int k){
    struct Node* n=createNode(a);
    struct Node* temp=*head;
    int i=1;
    while(temp->next!=NULL && i<k-1){
        temp=temp->next;
        i=i+1;
    }
    struct Node* b=temp->next;
    temp->next=n;
    n->next=b;
}
#include<stdio.h>
#include<stdlib.h>

struct Node{
    int data;
    struct Node* next;
};

struct Node* createNode(int a){
    struct Node* n=(struct Node *)malloc(sizeof(struct Node));
    n->data=a;
    n->next=NULL;
    return n;
}

void insertAtEnd(struct Node** head,int a){
    struct Node* newNode=createNode(a);
    if(*head==NULL){
        *head=newNode;
        return;
    }
    struct Node* temp=*head;
    while(temp->next!=NULL){
        temp=temp->next;
    }
    temp->next=newNode;
    
}

void insertAtK(struct Node** head,int a,int k){
    struct Node* n=createNode(a);
    struct Node* temp=*head;
    int i=1;
    while(temp->next!=NULL && i<k-1){
        temp=temp->next;
        i=i+1;
    }
    struct Node* b=temp->next;
    temp->next=n;
    n->next=b;
}