Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Fall-17
- #include<stdio.h>
- #include<stdlib.h>
- typedef struct x
- {
- int data;
- struct x *next;
- }x;
- x *head=NULL,*temp;
- void insertBetween(int a,int b)
- {
- x *c;
- c=(x*)malloc(sizeof(x));
- c->data=b;
- temp=head;
- while(temp->data!=a)
- {
- temp=temp->next;
- }
- c->next=temp->next;
- temp->next=c;
- temp=head;
- while(temp!=NULL)
- {
- printf("%d ",temp->data);
- temp=temp->next;
- }
- }
- void count()
- {
- int a=0;
- temp=head;
- while(temp!=NULL)
- {
- a++;
- temp=temp->next;
- }
- printf("\n%d",a);
- }
- int main()
- {
- x *a,*b,*c,*d;
- a=(x*)malloc(sizeof(x));
- b=(x*)malloc(sizeof(x));
- c=(x*)malloc(sizeof(x));
- d=(x*)malloc(sizeof(x));
- a->data=3;
- a->next=b;
- head=a;
- b->data=10;
- b->next=c;
- c->data=2;
- c->next=d;
- d->data=1;
- d->next=NULL;
- while(a!=NULL)
- {
- printf("%d ",a->data);
- a=a->next;
- }
- printf("\n");
- insertBetween(10,15);
- count();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement