Advertisement
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;
- struct node*previous;
- } node;
- node*head;
- void display()
- {
- node *list=head;
- while(list !=NULL)
- {
- printf("A: %d\n",list->a);
- printf("C: %c\n",list->ch);
- printf("\n");
- list=list->next;
- }
- }
- void insert_at_end(int aN,char chN)
- {
- node*N=(node*)malloc(sizeof(node));
- N->a=aN;
- N->ch=chN;
- N->next=NULL;
- N->previous=NULL;
- node*list=head;
- if(head==NULL)
- {
- head=N;
- }
- else
- {
- while(list->next!=NULL)
- {
- list=list->next;
- N->previous=list;
- }
- list->next=N;
- N->next=NULL;
- N->previous=list;
- }
- }
- 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;
- head->previous=NULL;
- }
- else
- temp->next = list->next;
- printf("%d is deleted from list\n", value);
- x = 1;
- free(list);
- break;
- }
- temp = list;
- list = list->next;
- list->previous=temp;
- }
- if(x==0)
- printf("Key not found!\n");
- }
- int main()
- {
- head=NULL;
- int x,af,l;
- char cf;
- insert_at_end(1,'A');
- insert_at_end(3,'b');
- insert_at_end(5,'c');
- insert_at_end(7,'d');
- insert_at_end(9,'e');
- printf("position:");
- scanf("%d",&x);
- delete_item(x);
- display();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement