2. //Operation on linked list :Insertion,Deletion, #include <iostream.h> #include<process.h> #include<conio.h> class node { private : int data; node  *link; public : friend class ll ist; }; class llist { node *p; public: llist(); ~llist(); void insfirst(T x); void inslast(T x); void insaft(T x,int pos); T del(T num); void display(); } ;  llist::llist() { p=NULL; } template <class T> llist<T>::~llist() { delete p; } void llist::insfirst(int num) { node*temp ; // add new node temp = new node ; temp -> data = num ; temp -> link = p ; p = temp ; }  void llist::inslast(int num) { node  *temp, *r ; // if the list is empty, create first node if ( p == NULL ) { p = new node; p -> data = num ; p -> link = NULL ; } else { // go to last node temp = p ; while ( temp -> link != NULL ) temp = temp -> link ; // add node at the end r = new node <T>; r -> data = num ; r -> link = NULL ; temp -> link = r ; } } void llist::insaft(T num,int loc) { node *temp, *r ; temp = p ; // skip to desired portion for ( int i = 0 ; i < loc ; i++ ) { temp = temp -> link ; // if end of linked list is encountered if ( temp == NULL ) { cout << "\nThere are less than " << loc << " elements in list" << endl ; return ; } } // insert new node r = new node ; r -> data = num ; r -> link = temp -> link ; temp -> link = r ; } T llist::del(T num) { node*old, *temp ; temp = p ; while ( temp != NULL ) { if ( temp -> data == num ) { // if node to be deleted is the // first node in the linked list if ( temp == p ) p = temp -> link ; // deletes the intermediate nodes in the linked list else old -> link = temp -> link ; // free the memory occupied by the node delete temp ; return num; } // traverse the linked list till the last node is reached else { // old points to the previous node old = temp ; // go to the next node temp = temp -> link ; } } cout << "\n\nElement " << num << " not found" ; return num; } void llist::display() { node *temp = p ; cout << endl ; // traverse the entire linked list while ( temp != NULL ) { cout << temp -> data << " " ; temp = temp -> link ; } } void operation(llist a) { int ch,no,loc; T x; do { cout<<"\n1.Insert at beg\n2.Insert after\n3.Insert at end\n"; cout<<"4.Delete any node \n cout<<5.Display list\n6.Exit"; cout<<"\n\nEnter your choice : "; cin>>ch; switch(ch) { case 1:cout<<"\nEnter element to insert : "; cin>>x; a.insfirst(x); break; case 2: cout<<"\nEnter element to insert : "; cin>>x; cout<<"\nEnter location after which you want to insert :"; cin>>loc; a.insaft(x,loc); break; case 3: cout<<"\nEnter element to insert : "; cin>>x; a.inslast(x); break; case 4: cout<<"\nEnter element to delete : "; cin>>x; a.del(x); break; case5: a.display(); break; case 6:exit(0); default :cout<<"Wrong Choice :"; }//switch }while(ch!=6);