# include # include struct link { char info[20]; struct link *next; }; int i; int number ; struct link *start=NULL,*p,*node; void create() { char ch; i=1; node=start; node->next = (struct link* ) malloc(sizeof(struct link)); node = node->next; /*first location is created and node is now holding the address of the first location. */ printf("\n Enter string for node: %d: ",i); scanf("%s", node->info); fflush(stdin); node->next = NULL; printf("\n Enter choice--'n' for break: "); ch = getche(); while(ch != 'n') { i=i+1; node->next = (struct link* ) malloc(sizeof(struct link)); node = node->next; printf("\n Enter string for node: %d: ",i); scanf("%s", node->info); node->next = NULL; printf("\n Enter choice-- 'n' for break: "); ch = getche(); } printf("\n Total nodes = %d\n", i); } void dis(struct link *n) { node=n->next; while(node) { printf("\n 0x%x ", node); printf("%s\n",node->info); node=node->next; } } void del(struct link *n) { int num=0; int number = 1; int del_node; node=n->next; p = n; printf("\n Input node number you want to delete:"); scanf(" %d", &del_node); while(node) { if(number == del_node) { p->next = node->next; free(node); num++; break ; } else { node = node->next; p = p->next; number ++; } } if(num!=0) { printf("\n Desired node is deleted.\n"); dis(start); } else printf("Deletion not possible."); } void main() { clrscr(); create(); dis(start); del(start); getch(); }
|
| Author: GLADWIN | Member Level: Gold | Revenue Score:  |
A good and very project.This is even useful for college students
|