#include<conio.h>
#include <string.h>
#include <iostream.h>
#include <process.h>

enum bool{f,t};
//*************************************************************************//
template <class type>
struct Node
{
type data;
Node *next;
};
//*************************************************************************//
template <class type>
class List
{
private:
Node<type> *head;
public:
List();
bool empty();
Node<type>* headptr();
void insert(type);
Node<type>* search(int);
void del(Node<type> *);
void delelements(List<int>);
int size();
void makeEmpty();
void display();
void printNode(Node<type> *);
};

template <class type>
List<type>::List()
{
head=NULL;
}

template <class type>
void List<type>::makeEmpty()
{
head=NULL;
}

template <class type>
bool List<type>::empty()
{
if (head==NULL)
	return t;
else
	return f;
}

template <class type>
Node<type>* List<type>::headptr()
{
Node<type>* temp=head;
return temp;
}

template <class type>
void List<type>::insert(type n)
{
Node<type> *ptr=new Node<type>;
Node<type> *curr=head,*before=head;
ptr->data=n;
if (empty())
    {
    ptr->next=NULL;
    head=ptr;
    }
else
    {
    while(curr->data<n && curr!=NULL)
	    {
	    before=curr;
	    curr=curr->next;
	    }
    if (curr==head)
       {
       ptr->next=head;
       head=ptr;
       }
    else
       {
       before->next=ptr;
       ptr->next=curr;
       }

    }
}
template <class type>
int List<type>::size()
{
int counter=0;
Node <type>*temp=head;
while (temp!=NULL)
{
counter++;
temp=temp->next;
}
return counter;
}

template <class type>
Node<type>* List<type>::search(int loc)
{
Node <type>*temp=head;
if(loc<=size())
{for(int i=1;i<loc;i++)
    temp=temp->next;
return temp;
}
else return NULL;
}

template <class type>
void List<type>::del(Node<type> *ptr)
{

  Node<type> *temp=head;


if (ptr!=NULL)
	{
	if (ptr==head)
		head=head->next;
	else
	{
	while (temp->next!=ptr)
		temp=temp->next;
	temp->next=ptr->next;
	}
	delete ptr;
	}
}

template <class type>
void List<type>::delelements(List<int> l)
{
Node<int> *temp=l.headptr();
Node<type>* arr[10];
for(int i=0;i<10;i++)
arr[i]=NULL;

i=0;
while(temp!=NULL && temp->data<=size())
{
arr[i]=search(temp->data);
temp=temp->next;
i++;
}

for(int j=0;j<i;j++)
	del(arr[j]);

}

template <class type>
void List<type>::display()
{
Node<type> *temp=head;
while(temp!=NULL)
	{
	cout<<temp->data;
	temp=temp->next;
	}
}

template <class type>
void List<type>::printNode(Node<type> *ptr)
{
cout<<ptr->data;
}

void main()
{
List<char> l;
char el;
List<int> l1;int index;
Node <char> *loc;
int choice,n;
for(;;)
{
clrscr();
gotoxy(20,4);
cout<<"\n1- ADD NEW ELEMENT TO THE LIST.\n2- DISPLAY THE LIST.\n3- SEARCH FOR ELEMENT.\n4- DELETE ELEMENTS WHOSE POSITIONS ARE IN A LIST.\n5- FIND THE SIZE OF THE LIST.\n6- EXIT.";
gotoxy(25,13);
cout<<"ENTER YOUR CHOICE >>";cin>>choice;
switch(choice)
{
case 1:clrscr();cout<<"ENTER THE ELEMENT >>";cin>>el;
       l.insert(el);break;
case 2:clrscr();l.display();getch();break;
case 3:clrscr();cout<<"ENTER THE LOCATION OF THE ELEMENT >> ";cin>>n;loc=l.search(n);
       if(loc!=NULL)
	l.printNode(loc);
	else
	cout<<"\nELEMENT NOT FOUND" ;getch();break;
case 4:clrscr();cout<<"HOEW MANY ELEMENTS DO YOU WANT TO DELETE ?? ";cin>>n;
       cout<<"ENTER THE LOCATIONS OF ELEMENTS TO BE DELETED SEPERATED BY A SPACE >> ";
       for(int i=1;i<=n;i++)
	  {
	  cin>>index;
	  l1.insert(index);
	  }
	l.delelements(l1);
	l1.display();
	l1.makeEmpty();
	getch();break;
case 5:clrscr();cout<<"SIZE IS >> "<<l.size();getch();break;
case 6:exit(0);
}

}


}