#include <stdio.h> #include <stdlib.h> struct dll { struct dll* prev; int data; struct dll* next; }; int main() { struct dll* p1, *p2, *p3, *temp; p1 = malloc(sizeof(struct dll)); p2 = malloc(sizeof(struct dll)); p3 = malloc(sizeof(struct dll)); p1->prev = NULL; p1->data = 1; p1->next = p2; p2->prev = p1; p2->data = 2; p2->next = p3; p3->prev = p2; p3->data = 3; p3->next = NULL; struct dll * add=NULL; int count = 0; printf("add of p1::%p add of p2::%p add of p3::%p \n", p1, p2, p3); for ( temp = p1; temp != NULL; temp = temp->next ){ count++; } printf("no of nodes %d\n", count); //puts("enter the addresss of node to delete it"); add=&p2; printf("address of node which i wanna delete::%p\n",*add); temp = p1; printf("temp:%p\n",temp); while(temp!=NULL){ if (temp->next == add) { printf("temp in for loop:%p\n",temp); temp->next=temp->next->next; temp->next->next->prev=temp; printf("%p %p\n",temp->next,temp->next->next->prev); free(temp); temp = NULL; } temp = temp->next; break; } puts("after deletion attempted"); count =0; for ( p1; p1!= NULL; p1 = p1->next ){ count++; } printf("no of nodes %d\n", count); free(p1); p1 = NULL; free(p2); p2 = NULL; free(p3); p3 = NULL; return 0; }
add of p1::0x8512008 add of p2::0x8512018 add of p3::0x8512028<br /> no of nodes 3<br /> address of node which i wanna delete::0x8512018<br /> temp:0x8512008<br /> after deletion attempted<br /> no of nodes 3
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)