#include<iostream.h>

struct node
{
	int data;
	node *next;
};
class linkedlist
{
public:
	linkedlist();
	~linkedlist();
	void add_to_top(int);
	void add_after(int,int);
	void add_to_end(int);
	void del(int );
	void display();
private:
	node *start;
};
linkedlist::linkedlist()
{
	start=NULL;
}
void linkedlist::add_to_top(int d)
{
	node *temp=new node;
	temp->data=d;
	temp->next=start;
	start=temp;
}
void linkedlist::add_to_end(int d)
{
	node *temp=new node;
	temp->data=d;
	temp->next=NULL;
	if(start==NULL)
	start=temp;
	else
	{
		node *temp2;
		while(temp2->next!= NULL)
		temp2=temp2->next;
		temp2->next=temp;
	}
}
	void linkedlist::add_after(int n,int d)
	{
		node *temp=new node;
		temp->data=d;
		if(start==NULL)
			start=temp;
		else
		{
			node *temp2=start;
		for(int i=0;i<n;i++)
		{
			temp2=temp2->next;
			temp2->next=temp;
			temp->next=temp2->next;
		}
		}
	}

		void linkedlist::del(int n)
		{
			node*temp=start;
			node*temp2=temp;
			while(temp->next !=NULL && temp->data !=n)
				temp2=temp;
			temp=temp->next;

		
		
			temp2->next=temp->next;
			delete temp;
		}
		linkedlist::~linkedlist()
		{
			node*temp=start;
			while(start->next !=NULL )
			{
				temp=start->next;
			delete start;
			start=temp;
			}
			start=NULL;
		}
		//------------------------------------------------
		void linkedlist::display()
		{
			node *temp=start;
			if(start==NULL)
				cout<<"list is empty";
			else
				if(start->next==NULL)
					cout<<start->data;
				else
			while(start->next!= NULL)
			{
				cout<<start->data;
				start=start->next;

			}
		}





int main()
{
	linkedlist obj;
	obj.add_to_top(3);
	obj.add_to_top(5);
	obj.add_to_end(10);
	obj.display();


return 0;
}
