#include #include #include #include struct stud { int roll; char name[20]; char address[30]; stud *next; }; void main() { stud *first, *last, *x; int i,n; cout << "Enter the size of the list "; cin >> n; if( n <= 0 ) cout << "Invalid size entered"; first = new stud; cout << "Enter data of first node:(Name , Roll No, Address) \n"; cin >> first->name >> first->roll ; gets(first->address); first->next = NULL; last = first; for(i=0; i<(n - 1); i++) { x = new stud; cout << "Enter data of Node " << (i+2) << " \n"; cin >> x->name ; cin >> x->roll ; gets(x->address) ; x->next = NULL; last->next = x; last = x; } stud *temp; temp = new stud; temp = first; int ch, found = 0; cout << "The search is to be done by: \n\n"; cout << " 1. By Name \n 2. By Roll Number \n 3. By Address \n"; cout << "Enter your choice: "; cin >> ch; if(ch == 1) { char value[30]; cout << "Enter value to be Searched: "; gets(value); while(temp != NULL) { if(!(strcmp(temp->name , value)) ) found++; temp = temp->next ; } } else if(ch == 2) { int value; cout << "Enter the value to be searched: "; cin >> value; while(temp != NULL) { if(temp->roll == value) found++; temp = temp->next ; } } else if(ch == 3) { char value[30]; cout << "Enter value to be Searched: "; gets(value); while(temp != NULL) { if(!(strcmp(temp->address , value)) ) found++; temp = temp->next ; } } if(found > 0) { cout << "Element found "; getch(); } else { cout << "Element not found "; getch(); } }