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);
}
0 Comments