#include #include #include #include #include typedef enum {false,true} bool; typedef struct record* ptr ; struct record { int data; ptr next; }; ptr root,node; char choice; void create() { int n=1; root=NULL; while (n!=0) { cout << "enter no: "; cin >> n; node = new record; node->data=n; node->next=root; root=node; } } void display() { node=root; while (node!=NULL) { cout << node->data<<' '; node=node->next; } } void insert() { int i,n; ptr temp; cout << "Enter no to insert: "; cin >> i; cout << "Insert after(0 for at head): "; cin >> n; node=root; if (n==0) { temp=new record; root=temp; root->data=i; temp->next=node; } else { while (node->data!=n) node=node->next; temp=new record; temp->data=i; temp->next=node->next; node->next=temp; } } void del() { int n; cout << "Enter the no to delete (0 for head): "; cin >> n; ptr back; back=node=root; if (n==0) { root=node->next; delete node; } else while (node->data!=n) { back=node; node=node->next; } back->next=node->next; delete node; } void search() { int n; bool found; cout << "enter no to find: "; cin >> n; node=root; while ((node!=NULL)||(found==0)) { if (node->data==n) found=true; node=node->next; }; if (found==true) cout << "found"; else cout<<"not found"; } void menu() { cout<<"\n\nEnter a choice\n"; cout<<"1:display,s:search,i:insert,d:delete,x:exit "; cin >> choice; } int main() { clrscr(); create(); do { menu(); switch (choice) { case '1':display();break; case 's':search();break; case 'i':insert();break; case 'd':del();break; } } while (choice!='x'); return 0; }