#include<iostream>
using namespace std;
class node
{
 public:
 int info;
 node *link;
}*start=NULL;
void AddAtBeg(int n)
{
 node *temp=new node;
 temp->info=n;
 temp->link=start;
 start=temp;
}
void AddAtLast(int n)
{
 node *temp=new node;
 node *ptr=start;
 while(ptr->link!=NULL)
 {
 ptr=ptr->link;
 }
 temp->info=n;
 ptr->link=temp;
 temp->link=NULL;
}
void AddAtLoc(int n, int loc)
{
 node *temp=new node;
 node *ptr=start;
 node *ptr1;
 temp->info=n;
 for(int i=0; i<loc-1; i++)
 {
 ptr1=ptr;
 ptr=ptr->link;
 }
 temp->link=ptr1->link;
 ptr1->link=temp;
}
void Display()
{
 node *ptr=start;
 while(ptr!=NULL)
 {
 cout<<ptr->info<<"->";
 ptr=ptr->link;
 }
}
void DeleteFromFirst()
{
 node *temp=start;
 start=temp->link;
}
void DeleteFromLoc(int loc)
{
 node *ptr=start;
 node *ptr1;
 for(int i=0; i<loc-1; i++)
 {
 ptr1=ptr;
 ptr=ptr->link;
 }
 ptr1->link=ptr->link;
}
void DeleteFromLast()
{
 node *ptr=start;
 node *ptr1;
 while(ptr->link!=NULL)
 {
 ptr1=ptr;
 ptr=ptr->link;
 }
 ptr1->link=NULL;
}
void Search(int n)
{
 node *ptr=start;
 int count=1;
 while(ptr!=NULL)
 {
 if(ptr->info==n)
 {
 cout<<"nItem found at Location "<<count;
 break;
 }
 else
 {
 ptr=ptr->link;
 }
 }
 if(ptr==NULL)
 {
 cout<<"nitem doest not exists in the list";
    }
}
int main()
{
 AddAtBeg(20);
 AddAtBeg(30);
 AddAtBeg(40);
 AddAtBeg(60);
 AddAtBeg(70);
 AddAtBeg(80);
 AddAtLoc(4,3);
 DeleteFromFirst();
 DeleteFromLoc(3);
 AddAtLast(100);
 DeleteFromLast();
 Display();
 Search(70);
 return 0;
}