# help me to knpow what is wrong with this

*label*Programming

*timer*Asked: Dec 6th, 2013

**Question description**

#include <stdio.h>

#include <string.h>

struct Node;

typedef Node *PtrToNode;

struct Node

{

char element;

PtrToNode Next;

};

void push(PtrToNode L, char x)

{

PtrToNode p=new Node;

p->element=x;

p->Next=L->Next;

L->Next=p;

}

char pop(PtrToNode L)

{

PtrToNode q=L->Next;

int x=q->element;

L->Next=L->Next->Next;

delete q;

return x;

}

char top(PtrToNode L)

{

PtrToNode q=L->Next;

int x=q->element;

return x;

}

bool isEmpty(PtrToNode L)

{

if(L-> element== NULL)

return true;

else

return false;

}

int Priority(char p)

{

switch(p)

{

case'+': return 1;

case'-': return 1;

case'*': return 2;

case'/': return 2;

case'%': return 2;

}

}

int EvalExpression(char c[])

{

PtrToNode s=new Node;

s->Next=NULL;

int len=strlen(c);

for(int i=0;i<len;i++)

{

if(c[i]>='1'&&c[i]<='9')

{

push(s,c[i]);

}

else

{

char y=pop(s)-48;

char x=pop(s)-48;

int z=0;

switch(c[i])

{

case'+': z=x+y;break;

case'-': z=x-y;break;

case'*': z=x*y;break;

case'/': z=x/y;break;

case'%': z=x%y;break;

}

char l=z+48;

push(s,l);

}

}

int r=pop(s)-48;

return(r);

}

bool check(char x[])

{

PtrToNode L=new Node;

L->Next=NULL;

for(int i=0;i<strlen(x);i++)

{

if((x[i]=='(')||(x[i]=='[')||(x[i]=='{'))

push(L,x[i]);

if((x[i]==')')||(x[i]==']')||(x[i]=='}'))

{

if(L->Next==NULL)

return false;

char c=pop(L);

if((x[i]==')')&&(c!='('))

return false;

if((x[i]=='}')&&(c!='{'))

return false;

if((x[i]==']')&&(c!='['))

return false;

}

}

if(L->Next!=NULL)

return false;

else return true;

}

char* intopost(char c[])

{

int len=strlen(c); // to get the length of the string c which is written in infix notation

char *b=new char [len];

int counter=0;

PtrToNode s=new Node;

s->Next=NULL;

for(int i=0;i<len;i++)

{

if(c[i]>='1'&&c[i]<='9')

{

b[counter++]=c[i];

}

else

{

if(isEmpty(s))

{

push(s,c[i]);

}

else if(Priority(c[i])>Priority(top(s)))

{

push(s,c[i]);

}

else

{

while(isEmpty(s)==false)

b[counter++]=pop(s);

push(s,c[i]);

}

}

}

while(isEmpty(s)==false)

b[counter++]=pop(s);

b[counter]='\0';

return b;

}

void main()

{

char c[20];

printf("plz enter a mathematical in infix notation:\n");

scanf("%s",c);

char *b;

b=intopost(c);

printf("%s",b);

int x=EvalExpression(b);

printf("\n%d\n",x);

}