Deleting the Node with a Given ITEM of Information Example Program – इस Algorithm के आधार पर हम निम्नानुसार एक Program Create कर सकते हैं जो किसी Linked List के उस Node को Delete किया गया है जिसमें ITEM प्राप्त होता है।
[code] Program of Deletion of a Given Node #include <stdio.h> #include <conio.h> #include <alloc.h> void main(void) { int i, ITEM; struct LIST { int INFO; struct LIST *LINK; }START, *NODE, *LOC, *LOCP; START.LINK = NULL; // Empty List NODE = &START; // Points to the Start of Linked List for(i=1; i<10; i++) // Linked List Creation { NODE->LINK = (struct LIST *)malloc(sizeof(struct LIST)); NODE->INFO = i; NODE=NODE->LINK; NODE->LINK = NULL; } //Remove the Number fflush(stdin); printf("\nEnter Number You want to Delete [ 1 to 9 ] "); scanf("%d", &ITEM); printf("\n\nLIST Before Deletion of VALUE = %d \n\n", ITEM); NODE = &START; // Points to the Start of Linked List while(NODE != NULL) { printf("%d\t", NODE->INFO); NODE = NODE->LINK; } LOC = START.LINK; LOCP = &START; while(LOC) { if(LOC->INFO == ITEM) { LOCP->LINK = LOC->LINK; free(LOC); break; } else { LOC = LOC->LINK; LOCP = LOCP->LINK; } } //Display the LIST LOC = &START; printf("\n\nLIST After Deletion VALUE = %d \n\n", ITEM); while(LOC != NULL) { printf("%d\t", LOC->INFO); LOC = LOC->LINK; } getch(); } Output Enter Number You want to Delete [ 1 to 9 ] 5 LIST Before Deletion of VALUE = 5 1 2 3 4 5 6 7 8 9 4253080 LIST After Deletion VALUE = 5 1 2 3 4 6 7 8 9 4253080 [/code]
ये Article इस वेबसाईट पर Selling हेतु उपलब्ध EBook Data Structure and Algorithms in Hindi से लिया गया है। इसलिए यदि ये Article आपके लिए उपयोगी रहा, तो निश्चित रूप से ये पुस्तक भी आपके लिए काफी उपयोगी साबित होगी।
Data Structure and Algorithms in Hindi | Page: 433 | Format: PDF