Tutorials(New)

Linked Lists

Binary Trees

Expression Converstion's

Infix To Postfix

Infix To Prefix

Postfix To Prefix

Postfix To Infix

Postfix Expression Evaluation

Windows Hooks

Splash Screen

Visual C++

C++

COM

.NET

C# 

ASP

ADO

Winform

 

Blogs............

VC++  Blog

Data structures Blog

.Net Blog

C#.Net Blog

VB.Net Blog

ASP.Net Blog

ADO.Net Blog

Winform Blog

WCF / WPF Blog

Job Openings

Operating Systems Faqs

Sybase Faq's

Download free e-books

All scripting Faq's

Oracle Faq's

All technical Faq's

Hasya-Vyang 

hindi kavitae

HR, Car, Finance Faq's

Finance & Investment

All Freshers Resources

All Placement Papers

QA and testing Faq's

Sql Server Faq's

Interview Puzzles

Mainframes Faq's

Java Faq's

Sap Faq's

GDI+
Ado.Net Tutorial
Asp.Net Tutorial
Lectures videos
Winform Tutorial
C#.Net Tutorial
Programming Tips And Tricks
Visual C++ Tutorial
Ado.net Tutorial
ActiveX Controls Tutorial
ATL COM Tutorial
COM Tutorial
Managed C++

The Buddha And His Dhamma
Bea WebLogic Interviews
TCL Programming FAQ's
Computer Science Notes
Discrete Mathematics notes
Database Management System(DBMS) Faqs
Professional Practices Faqs
Lotus Notes Faqs
Beautiful advertisements
Programming interview Questions and answers Blog List
Human Resource Tips
Tips for Windows XP Systems
Tips for Internet and Computer users
Tips for better e-mail etiquette
JavaScript Faq's
VB Script FAQ's
HTML Faq's
Perl Scripting FAQ's
Winrunner Faq's

Linux FAQ's
CCNA cisco Certification
Data WareHousing Interview
Microsoft SharePoint Interview
C++ Interview
Siebel Customer Relationship Management FAQ's
C Programming Step by step learning
Unix FAQ's

Sample Source Code for all languages
Technical Certifications

Source Code

Certifications

Misceleneous technical Faq's
 

So far we have seen programs which could translate expressions from infix to postfix to prefix notation to any such combination. The virtue of a postfix notation is that it enables easy evaluation of expressions. To begin with, the need for parentheses is eliminated. Secondly, the priority of the operators is no longer relevant. The expression may be evaluated by making a left to right scan, stacking operands, and evaluating operators using operands from the stack and finally placing the result onto the stack. This evaluation process is much simpler than attempting a direct evaluation of infix notation. The following program implements the postfix expression evaluation algorithm.  

#define MAX 25 

void push ( int * , int * , int ) ; 

int pop ( int *, int * ) ; 

main( ) 

char str[MAX], *s ; 

int n1, n2, n3, nn ; 

int stack[MAX], top = -1 ; 

clrscr(); 

printf ( "\nEnter the postfix expression to be evaluated: " ) ; 

gets ( str ) ; 

s = str ; 

while ( *s ) 

/* skip whitespace, if any */ 

if ( *s == ' ' || *s == '\t' ) 

s++ ; 

continue ; 

/* if digit is encountered */ 

 if ( *s >= 48 && *s <= 57 ) 

nn = *s - '0' ; 

push ( stack, &top, nn ) ; 

else 

/* if operator is encountered */ 

n1 = pop ( stack, &top ) ; 

n2 = pop ( stack, &top ) ; 

switch ( *s ) 

case '+' : 

n3 = n2 + n1 ;break ; 

case '-' : 

n3 = n2 - n1 ;break ; 

case '/' : 

n3 = n2 / n1 ;break ; 

case '*' : 

n3 = n2 * n1 ;break ; 

case '%' : 

n3 = n2 % n1 ;break ; 

default : 

printf ( "Unknown operator" ) ; 

exit ( 1 ) ; 

push ( stack, &top, n3 ) ; 

s++ ; 

}  

printf ( "Result is : %d", pop ( stack, &top ) ) ; 

void push ( int *stk, int *sp, int item ) 

if ( *sp == MAX ) 

printf ( "\nStack is full" ) ; 

else 

*sp = *sp + 1 ; 

stk[*sp] = item ;

int pop ( int *stk, int *sp ) 

int item ; 

if ( *sp == -1 ) 

printf ( "\nStack is empty" ) ; 

return ( -1 ) ; 

else 

item = stk[*sp] ; 

*sp = *sp - 1 ; 

return ( item ) ; 

}