#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define SIZE  100
int count=0;
typedef struct node{
 int value;
 struct stack *next;
 struct stack *prev;
}stack;

stack *bottom=NULL;
stack *top=NULL;

stack *createnode(int a)
{
 stack *newstack;
 newstack=(stack*)calloc(1,sizeof(stack));
 newstack->value=a;
 newstack->prev=NULL;
 newstack->next=NULL;
 return newstack;
}

int isempty()
   {
       if(count==0)
       {return 1;}
       else
       {return 0;}
    }

int isfull()
    {
     if(count==SIZE)
     {return 1;}
     else
     {return 0;}
    }

void push(int a)
{   if(isfull()==1)
   {
    printf("overflow condition: stack full");
   }
 else
   {count+=1;
 stack *newstack = createnode(a);
 if(bottom==NULL)
 {
 bottom=newstack;
 top=bottom;
 }
 else
 {
  top->next=newstack;
  newstack->prev=top;
  top=newstack;
 }
   }
}
char peek()
{
    return top->value;
}
char pop()
    {   if(isempty()==1)
        {
         printf("underflow condition:empty stack");
        }
        else
        {if(count==1)
        {   int c;
         c=top->value;
         top=NULL;
         bottom=NULL;
         count=count-1;
         return c;

        }
        else
     {int c;
     c=top->value;
  top=top->prev;
  top->next=NULL;
  count=count-1;
  return c;

     }
       }
    }
    char plus=43;
    char multi=42;
    char divi=47;
    char power=94;
    char left=40;
    char right=41;
    char subtract=45;
void *postfix_evaluation(char *string,int length)
{  int i; stack operators;
 for(i=0;i<length;i++)
 {
  char c;
  c=string[i];
  if(c==plus || c==subtract || c==multi || c==divi || c==power)
  {
        int a =pop();
        int b=pop();
        if(c==plus)
        {
                int result=b+a;
                push(result);
             //   printf("%d",result);
        }
        if(c==subtract)
        {
                int result=b-a;
                push(result);
        }
        if(c==multi)
        {
                int result=b*a;
                push(result);
        }
        if(c==divi)
        {
                int result=b/a;
                push(result);
        }
        if(c==power)
        {
                int result=pow(b,a);
                push(result);
        }
        }
        else
        {     int k=c-'0';
              push(k);
          //    printf("%d",k);
        }
/*  if(i==length-1)
  {    
        int d=pop();
        printf("%d",d);
  }
*/  
  }
  int d=pop();
  printf("%d",d);
}

// driver code , the main function

int main(void)
{   char inversion[200];
 printf("give the postfix expression\n");
 scanf("%s",&inversion);
 int longer=strlen(inversion);
 postfix_evaluation(inversion,longer);

 return 0;
}
