#include <stdio.h>
#include <malloc.h>
#include <conio.h>




//تركيبة القائمة المتصلة

//////////////////////////////
struct  Node             /////			   
{						 /////	
	int info;			 /////	
	struct Node *next;   /////   
};						 /////
//////////////////////////////


// تعريف مؤشر الى العقدة واستخدامه في تعريف بقية المؤشرات الى القائمة

/////////////////////////////
typedef struct Node * PTR; //
/////////////////////////////

//الدوال اعمليات على القائمة

///////////////********************/////////////////////////////////////////////////
///  
                                                                             //
PTR   Getnode();						 //دالة انشاء عقدة                        //
PTR	  push( PTR list, int x );			//دالة انشاء عقدة من  اخر القائمة			  //
void  PrintList( PTR  list );		 //دالة طباعة القيم التي في  القائمة كلها     //

///																				  //																			
///////////////********************/////////////////////////////////////////////////
PTR pop( PTR list, int * px );




int main()
{
	
	PTR LIST;
	int x,y,t;
	char c;


	LIST = NULL;
	
	c = getchar();

	while( c != '\n' )
	{
		if( ( c == 32 ) || ( c == '\t' ) );
		else if( ( c >= '0' ) && ( c <= '9' ) )
		{
			t = 0;

			while( ( c >= '0' ) && ( c <= '9' ) )
			{
				t = ( t*10 ) + (c - '0' );
				c = getchar();

			}
			ungetc(c,stdin);
			LIST = push(LIST,t); //call push

		}
		else if( ( c == '+' ) || ( c == '-' ) || ( c == '*' ) || ( c == '/' ) )
		{
			//x and y are pointers.

			LIST =  pop(LIST,&x);  //call pop
			LIST =  pop(LIST,&y);  // call pop

			switch( c )
			{
				case '+':
					LIST = push(LIST,x+y); //call push
					break;
				case '-':
					LIST = push(LIST,x-y); //call push
					break;
				case '*':
					LIST = push(LIST,x*y); //call push
					break;
				case '/':
					if( y > 0 )
					{
						LIST = push(LIST,x/y); //call push
						
					}
					else
					{
						printf("\n\aError y = %d < 0",y);
					}
					break;
			}


		}
		
		c = getchar();

	}
	
	LIST =  pop(LIST,&x);  //call pop and result x
	printf("\n\n ******** result = %d ********\n\n",x);
	
	return  0;
}



//جسم دالة انشاء عقدة
PTR  Getnode()
{
	PTR p = (PTR) malloc( sizeof( struct Node ) );

	return  p;
}


//دالة اضافة حلقة للقائمة من عند اخر القائمة
PTR   push( PTR list, int x)
{

		if( list == NULL )
		{
			list = Getnode();
			list->info = x;
			list->next = NULL;
		}
		else
		{

			PTR p = Getnode();
			p->info = x;
			p->next = list;
			list    = p;
	
		}

		return list;
	
}

PTR pop( PTR list, int * px )
{
	
	PTR p = list;

	if( list == NULL )
	{
		printf("Satak is empty\n");
		return NULL;
	}

	else
	{
		
		*px = p->info;
		list = p->next;
		free(p);
		p = NULL;	
		return list;
	}
}

