#include #include #include struct node { int no; struct node *pre,*next; }; struct node *start=NULL,*last=NULL; void Append() { struct node *n; n=(struct node*)malloc(sizeof(struct node)); printf("\nEnter no"); scanf("%d",&n->no); n->next=NULL; if(start==NULL) { start=last=n; start->pre=NULL; return; } last->next=n; n->pre=last; last=n; } void ftraverse() { struct node *p=start; if(start==NULL) { printf("\n Empty Link List"); return; } while(p!=NULL) { printf(" %d",p->no); p=p->next; } } void btraverse() { struct node *p=last; if(last==NULL) { printf("\n Empty Link List"); return; } while(p!=NULL) { printf(" %d",p->no); p=p->pre; } } void Search(struct node *p) { int val; if(p==NULL) { printf("\n Empty Link List"); return; } printf("\n Enter element to be SEARched "); scanf(" %d",&val); if(p==start) { while(p!=NULL) { if(val==p->no) { printf("\n FOUnd"); return; } p=p->next; } } else { while(p!=NULL) { if(val==p->no) { printf("\n FOUNd"); return; } p=p->pre; } } printf("\n NOT Found"); } void Update(struct node *p) { int val; if(p==NULL) { printf("\nEmpty LINK lIST"); return; } printf("enter element to be UPDated"); scanf("%d",&val); if(p==start) { while(p!=NULL) { if(val==p->no) { printf("Enter no "); scanf("%d",&p->no); printf("\nUpdated"); return; } p=p->next; } } else { while(p!=NULL) { if(val==p->no) { printf("\n Enter new no"); scanf("%d",&p->no); printf("\nUPDated"); return; } p=p->next; } } printf("\n %d NOT Found",val); } void main() { int ch; clrscr(); do { printf("\n 1 Append"); printf("\n 2 Forward TRAverse"); printf("\n 3 BAckward TRAverse"); printf("\n 4 Search from Start"); printf("\n 5 Search from LAST"); printf("\n 6 UPdate from start"); printf("\n 7 Update from LAST"); printf("\n 0 EXIT"); printf("\n Enter your choice"); scanf("%d",&ch); switch(ch) { case 1:Append(); break; case 2:ftraverse(); break; case 3:btraverse(); break; case 4: Search(start); break; case 5: Search(last); break; case 6: Update(start); break; case 7: Update(last); break; case 0: break; default: printf("\n Invalid Choice"); } }while(ch!=0); getch(); }