diff --git a/Insert.c b/Insert.c new file mode 100644 index 0000000..41403d5 --- /dev/null +++ b/Insert.c @@ -0,0 +1,84 @@ +#include +#include + +struct Node +{ + int data; + struct Node *next; + +}*first=NULL; + +void create(int A[],int n) +{ + int i; + struct Node *t,*last; + + first=(struct Node*)malloc(sizeof(struct Node)); + first->data=A[0]; + first->next=NULL; + last=first; + + for(i=1;idata=A[i]; + t->next=NULL; + last->next=t; + last=t; + } +} +void Display(struct Node *p) +{ + while(p!=NULL) + { + printf("%d ",p->data); + p=p->next; + } +} +void Insert(struct Node *p,int index,int x) +{ + struct Node *t; + int i; + + if(index<0||index>count(p)) + return; + + t=(struct Node *)malloc((sizeof(struct Node))); + t->data=x; + + if(index==0) + { + t->next=first; + first=t; + } + else + { + for(i=0;inext; + + t->next=p->next; + p->next=t; + + } +} +int count(struct Node *p) +{ + int l=0; + while(p) + { + l++; + p=p->next; + } + return l; +} +int main() +{ + int A[]={10,20,30,40,50}; + create(A,5); + + Insert(first,0,5); + + Display(first); + return 0; + +}