Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #include<string.h>
- struct node
- {
- int data;
- struct node* link;
- };
- struct node* head=NULL;
- void insert(int data)
- {
- struct node* temp=(struct node*)malloc(sizeof(struct node));
- temp->data=data;
- temp->link=NULL;
- if(head==NULL)
- {
- head=temp;
- return;
- }
- struct node*p=head;
- while(p->link!=NULL)
- {
- p=p->link;
- }
- p=p->link=temp;
- }
- void delet()
- {
- struct node *p,*q;
- p=q=head;
- int i;
- for(i=1;i<4-1;i++)
- {
- p=p->link;
- }
- q=p->link;
- p->link=q->link;
- q->link=NULL;
- free(q);
- }
- void Insert_At_Position()
- {
- struct node* temp=(struct node*)malloc(sizeof(struct node));
- int data;
- printf("Enter noda data which you insert 5 between 4:");
- scanf("%d",&data);
- temp->data=data;
- temp->link=NULL;
- struct node* p;
- p=head;
- int i;
- for(i=1;i<3-1;i++)
- {
- p=p->link;
- }
- temp->link=p->link;
- p->link=temp;
- }
- display()
- {
- struct node* p=head;
- while(p!=NULL)
- {
- printf("%d ",p->data);
- p=p->link;
- }
- printf("\n");
- }
- int main()
- {
- insert(2);
- insert(5);
- insert(4);
- insert(3);
- insert(1);
- display();
- printf("After 3 delete\n");
- delet();
- display();
- Insert_At_Position();
- display();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement