/*Coded By Md Shoriful Islam ID: 12108048 Batch:13*/ #include #include struct node { int sa_info; struct node *NEXT; }; struct node *pos1 = NULL; struct node *LAST = NULL; void sa_input(int); int sa_del(int); void sa_output(void); struct node *sa_find (int); int main() { int n1, n2, select; struct node *location; while(1) { printf("Select an option"); printf("\n1 - Insert"); printf("\n2 - Delete"); printf("\n3 - Search"); printf("\n4 - Print"); printf("\n5 - Exit"); printf("\nEnter your choice: "); scanf("%d", &select); switch(select) { case 1: { printf("\nEnter the element to be inserted into the linked list: "); scanf("%d",&n1); sa_input(n1); printf("\n%d successfully inserted into the linked list!",n1); break; } case 2: { printf("\nEnter the element to be deleted from the linked list: "); scanf("%d",&n1); n2=sa_del(n1); if(n2==-9999) printf("\n%d is not present in the linked list\n",n1); else printf("\nElement %d successfully deleted from the linked list\n",n2); break; } case 3: { printf("\nEnter the element to be searched: "); scanf("%d",&n1); location=sa_find(n1); if(location==NULL) printf("\n%d is not present in the linked list\n",n1); else { if(location==LAST) printf("\nElement %d is the last element in the list",n1); else printf("\nElement %d is present before element %d in the linked list\n",n1,(location->NEXT)->sa_info); } break; } case 4: { sa_output(); break; } case 5: { printf("\nEND"); exit(1); break; } default: { printf("\nIncorrect choice. Please try again."); break; } } } } void sa_input(int value) { struct node *pr = (struct node*)malloc(sizeof(struct node)); pr->sa_info = value; if(pos1==NULL) { pos1 = LAST = pr; pr->NEXT=NULL; } else { LAST->NEXT = pr; pr->NEXT = NULL; LAST = pr; } } int sa_del(int value) { struct node *LOC,*TEMP; int i; **value; LOC=sa_find(i); if(LOC==NULL) return(-9999); if(LOC==pos1) { if(pos1==LAST) pos1=LAST=NULL; else pos1=pos1->NEXT; return(value); } for(TEMP=pos1; TEMP->NEXT!=LOC; TEMP=TEMP->NEXT) ; TEMP->NEXT=LOC->NEXT; if(LOC==LAST)LAST=TEMP; return(LOC->sa_info); } struct node *sa_find (int value) { struct node *pr; if(pos1==NULL) return(NULL); for(pr=pos1; pr!=LAST; pr=pr->NEXT) if(pr->sa_info==value) return(pr); if(LAST->sa_info==value) return(LAST); else return(NULL); } void sa_output() { struct node *pr; if(pos1==NULL) { printf("\n\tEmpty List!!"); return; } printf("\nLinked list elements:\n"); if(pos1==LAST) { printf("\t%d",pos1->sa_info); return; } for(pr=pos1; pr!=LAST; pr=pr->NEXT) printf("%d ",pr->sa_info); printf("%d\n",LAST->sa_info); }