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_item(int value)
- {
- node *list = head, *temp=NULL;
- int x = 0;
- while(list!=NULL)
- {
- if(list->a==value)
- {
- if(temp==NULL)
- head = list->next;
- else
- temp->next = list->next;
- printf("%d is deleted from list\n", value);
- x = 1;
- free(list);
- break;
- }
- temp = list;
- list = list->next;
- }
- if(x==0)
- printf("Key not found!\n");
- }
- int main()
- {int value;
- head=NULL;
- insert_end(5,'p');
- insert_end(4,'r');
- insert_end(2,'u');
- printf("ENTER Value FOR DELETE:");
- scanf("%d",&value);
- delete_item(value);
- display();
- }
Advertisement
Add Comment
Please, Sign In to add comment