Question description Dr.Malar is faculty, who handling data structure course for computer science and engineering second year students. one day this faculty was handling very interesting topic in data structure such that Linked List, she has given the following explanation for Linked list concept. "Linked List is a sequence of links which contains items. Each link contains a connection to another link. Linked list is the second most-used data structure after array. Following are the important terms to understand the concept of Linked List. Link − Each link of a linked list can store a data called an element. Next − Each link of a linked list contains a link to the next link called Next. LinkedList − A Linked List contains the connection link to the first link called First." During this lecture time, last bench students was making continuous disturbance by making unwanted noise. So the faculty decided to conduct test on the topic of Linked List. the question was given to last bench students that is, The new node is added at given position P of the given Linked List. For example if the given Linked List is 5->10->15->20->25 and we add an item 30 at Position 3, then the Linked List becomes 5->10->30->15->20->25.
C Program


#include<stdio.h>

#include<stdlib.h>

struct node{

    int data;

    struct node *next;

};

struct node *head=NULL;

void create(){

    int n,i,x;

    struct node *t,*p;

    scanf("%d",&n);

    for(i=0;i<n;i++)

    {

        scanf("%d",&x);

        p=(struct node*)malloc(sizeof(struct node));

        p->data=x;

        p->next=NULL;

        if(head==NULL)

            head=t=p;

        else

        {

            t->next=p;

            t=p;

        }

    }

}

int in_pos(int n){

    int p,x,i;

    struct node *t=head,*q;

    scanf("%d%d",&p,&x);

    q=(struct node*)malloc(sizeof(struct node));

    q->data=x;

    if(p==1){

        q->next=head;

        head=q;

        return 0;

    }

    for(i=1;i<p-1;i++)

        t=t->next;

    q->next=t->next;

    t->next=q;

    return 0;

}

int main(){

    struct node *t;

    create();

    in_pos(0);

    printf("Linked List:");

    for(t=head;t;t=t->next)

        printf("->%d",t->data);

}