Postfix Evaluation in C

  /* Evaluating postfix */ #include <stdio.h> #include <math.h> #define SIZE 50 /* Size of Stack */ #include <ctype.h> int s[SIZE]; int top=-1; /* Global declarations */ push(int elem) { s[++top]=elem; } int pop() { return(s[top–]); } main() { char pofx[50],ch; int i=0,op1,op2; printf(“\n\nRead the Postfix Expression ? “); scanf(“%s”,pofx); while( (ch=pofx[i++]) != ‘\0’) { […]

Ackermann Function

Ackermann Function is the simplest example of a well defined total function which is compatible but not primitive recursive. It grows faster than an exponential function. /* Ackermann Function */ #include<stdio.h> #include<stdlib.h> int count = 0, indent = 0; int ackermann(int x, int y) { count++; if(x<0 || y<0) return -1; if(x==0) return y+1; if(y==0) […]

Infix Expression to Post-fix (Reverse police) Notation

Here we just look out the code on Infix to Postfix expression notation. It is also known as Reverse police method. Find the full code snippet below. Sample Code of Reverse Police Method /* Infix expression to post-fix (Reverse police) notation */ #include<stdio.h> #include<ctype.h> #define MAX 100 typedef struct stack { int data[MAX]; int […]