Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- typedef struct node
- {
- int a;
- char ch;
- struct node *next;
- } node;
- node *head;
- void display()
- {
- node *list=head;
- while(list !=NULL)
- {
- printf("\n\nA= %d ,C= %c\n",list->a,list->ch);
- list=list->next;
- }
- }
- void insert_end(int aN,char chN)
- {
- node *N=(node*)malloc(sizeof(node));
- N->a=aN;
- N->ch=chN;
- N->next=NULL;
- node *list=head;
- if(head==NULL)
- {
- head=N;
- list=N;
- }
- else
- {
- while(list->next!=NULL)
- {
- list=list->next;
- }
- list->next=N;
- }
- }
- void delete_pos(int pos)
- {
- node *list=head,*temp=NULL;
- int x=0;
- if(pos==1)
- {
- head=head->next;
- free(list);
- printf("KEY IS DELETED \n");
- return;
- }
- pos=pos-2;
- while(pos!=0)
- {
- list=list->next;
- pos--;
- if(list==NULL)
- return;
- }
- temp=list->next;
- list->next=temp->next;
- x=1;
- free(temp);
- if(x==1)
- {
- printf("KEY IS DELETED \n\n");
- }
- }
- int main()
- {int x;
- head=NULL;
- insert_end(5,'p');
- insert_end(4,'r');
- insert_end(2,'u');
- printf("ENTER POSITION FOR DELETE:");
- scanf("%d",&x);
- delete_pos(x);
- display();
- }
Advertisement
Add Comment
Please, Sign In to add comment