Reverse Polish notation (or RPN) is a mathematical notation wherein every operator follows all of its operands, in contrast to Polish notation, which puts the operator in the prefix position. It is also known as Postfix notation and is parenthesis-free as long as operator arities are fixed. The description "Polish" refers to the nationality of logician Jan Łukasiewicz, who invented (prefix) Polish notation in 1920s.
The Reverse Polish scheme was proposed in 1954 by Burks, Warren, and was independently reinvented by F. L. Bauer and E. W. Dijkstra in the early 1960s to reduce computer memory access and utilize the stack to evaluate expressions. The notation and algorithms for this scheme were extended by Australian philosopher and computer scientist Charles Hamblin in the mid-1950s.
During the 1970s and 1980s, RPN had some currency even among the general public, as it was widely used in handheld calculators of the time – for example, the HP-10C series and Sinclair Scientific calculators.
In computer science, postfix notation is often used in stack-based and concatenative programming languages. It is also common in dataflow and pipeline-based systems, including Unix pipelines.
Most of what follows is about binary operators. A unary operator for which the Reverse Polish notation is the general convention is the factorial
----------------------------------------------------------------------------------------------
A C PROGRAM TO IMPLEMENT EVALUATION OF POSTFIX EXPRESSION -STACK
APPLICATION
COMPILER EMPLOYED: DEV C++ COMPILER-4.9.9.2
SOURCE FILE SIZE :2 kb
EXE FILE SIZE :22 kb
NOTE: PLEASE INCLUDE THE DESIRED HEADER FILE
---------------------------------------------------------------------------------------------
C PROGRAM SOURCE & EXE DOWNLOAD:
Click download button to download
DISCLAIMER: The following program cannot be ensured of perfection.so any flaws in the program can be notified in the comments section.
----------------------------------------------------------------------------------------------
CODE:
# include
typedef struct
{
int A[100];
int TOP;
}STACK;
void PUSH(STACK *S,int X)
{
if(S->TOP==99)
printf("\n\n ERROR!!!! STACK OVERFLOW\n");
else
S->A[++S->TOP]=X;
}
int POP(STACK *S)
{
int X;
if(S->TOP<0) x="S-">A[S->TOP--];
return X;
}
}
int OPERATION(int P1,int P2,char OP)
{
switch(OP)
{
case '+':return P1+P2;
case '*':return P1*P2;
case '-':return P1-P2;
case '/':return P1/P2;
}
}
int EVALUATE(char pos[])
{
STACK S1;
int P1,P2,result,i;
S1.TOP=-1;
for(i=0;pos[i]!='\0';i++)
if(isdigit(pos[i]))
PUSH(&S1,pos[i]-'0');/*use to find the integer value of it*/
else
{
P2=POP(&S1);
P1=POP(&S1);
result=OPERATION(P1,P2,pos[i]);
PUSH(&S1,result);
}/*end of for loop*/
return POP(&S1);
}
int main()
{
char POSTFIX[100];
printf("\n EVALUATIO OF POST FIX EXPRESSIONS");
printf("\n\n NOTE: \n [1].ENTER A VALID POSTFIX STRING \n\n [2].OPERANDS ARE SINGLE DIGIT\n\n");
gets(POSTFIX);
printf("RESULT:%d",EVALUATE(POSTFIX));
system("pause");
return 0;
}
/*end of main*/
---------------------------------------------------------------------------------------------
Your's friendly,
[MOHANRAM.G],
ADMIN...
0 comments:
Post a Comment