
          //**********************************************************
          //* THIS PROGRAMM IS DONE BY:                              *
          //* IT IS USED TO :                                        *
          //**********************************************************


#include<iostream.h>
#include<math.h>


//-------------------------
// monome class
struct monome     
{
    int power;
    int coef;
    monome *next;    
};

//-------------------------
//header class
struct header    
{  
	monome *head;
	monome *cursor;
    int count;
};

//-------------------------
// the function
void Create();
monome * search_power(int);
void Add(monome *address,int);
void insert_in_front(int ,int);
monome*search_zero(int);
void Remove(monome *address);
void Garbage_collector();
void read(int,int);
void print_list();
void calcolate(int );



//-------------------------
header H;            //the number
monome *p;           //adrass
int power;           // for the power
int coef;
int x;            
monome *address;     //adrass



//------------------------------------------------
//دالة الانشاء
//------------------------------------------------

void Create()
{    
    monome *head=NULL;
    monome *cursor=NULL;
	int count=0;

}

//------------------------------------------------
//دالة البحث عن الأسس المتساوية
//------------------------------------------------

monome * search_power(int power)
{
    monome*p=H.head;
	while(p!=NULL)
	{

		if(p->power==power) 
			return p;
	}

	p=p->next;
	return 0;
}


//------------------------------------------------
//دالة الجمع
//------------------------------------------------


void Add(monome *address,int coef)
{
    address->coef=address->coef + coef;
     
}


//-----------------------------------------------
//دالة الادراج
//-----------------------------------------------


void insert_in_front(int power,int coef)
{
	cin>>power;
 	cin>>coef;
	while((power!=0)||( coef!=0))
	{
		monome * search_power();
		if(p==NULL)
		{
			p=new monome;
			p->power=power;
			p->coef=coef;
			p->next=NULL;;
			H.head=p;
			H.count++;
			p=p->next;	
		}
		if(address!=NULL)
			Add(address, coef);
		//&Iuml;&Ccedil;&aacute;&Eacute; &Ccedil;&aacute;&Egrave;&Iacute;&Euml; &Uacute;&auml; &Ccedil;&aacute;&Otilde;&Yacute;&Ntilde;
	}
}


//------------------------------------------------
//
//------------------------------------------------			


monome*search_zero(int coef)

{
    p=H.head;
	while(p!=NULL)
	{
 		if(p->coef==0)
        return p;
	}
	p=p->next;
	return 0;
}


//&Iuml;&Ccedil;&aacute;&Eacute; &Ccedil;&aacute;&Iacute;&ETH;&Yacute;
//------------------------------------------------
//
//------------------------------------------------


void Remove(monome *address)
{
    monome*s; 
    monome*p=H.head;
    s=p;
     if(p!=NULL)
     { int i=1;
     while((p!=NULL)&&(p!=address))
         s=p;
         p=p->next;
         i++;}
    if(p->coef==0)
    {    p=H.cursor;
        
            H.head->next=H.cursor->next;
    delete H.cursor;
    H.count--;}
    
}


//------------------------------------------------
//
//------------------------------------------------


void Garbage_collector()
{
    monome*search_zero( );
	cin>>coef;
	while(coef==0)
	{
		Remove(address);
	}
}


//------------------------------------------------
//دالة القراءة
//------------------------------------------------

//&Iuml;
void read(int coef,int power)
{
    cout<<"Enter coef" <<endl;
    cin>>coef;
    cout<<"Enter power" <<endl;
    cin>>power;

}
//------------------------------------------------
// دالة الطباعة
//------------------------------------------------

void print_list()

{
	monome *p;
	p=H.head;

	if (p==NULL)
	{
		cout<<"list is empty";
	}
	
	else
	{
		while(p!=NULL)
		{
			cout<<p->power<<" "<<p->coef<<" ";
			p=p->next;
		}
	}
}



//------------------------------------------------
// دالة الحساب
//------------------------------------------------

void calcolate(int x)
{
   
	double sum;
	p=H.head;
	cin>>x;
   
	while (p!=NULL)
	{
		sum=sum+((p->coef)*(pow(x,p->power)));
		p=p->next;
	}
   
	cout<<endl<<"the value of monome:\n"<<sum<<endl;
}


//***********************************************************
//-----------------------------------------------------------
//***********************************************************



void main()
{
	Create();
	insert_in_front(power,coef);
	monome * search_power(int power);
	void Add(monome *address,int coef);
	calcolate( x);
	read( coef, power);
	void print_list();
	void Remove(monome *address);
	monome*search_zero(int coef);
	Garbage_collector();
}


//*****************************************************************
//-----------------------------------------------------------------
//*****************************************************************