Cs301 Assignment Solution
Cs301 Assignment Solution
com/
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<ctype.h>
#define MAX 50
struct infix
char target[MAX] ;
char stack[MAX] ;
char *s, *t ;
int top ;
};
void main( )
struct infix p ;
char expr[MAX] ;
initinfix ( &p ) ;
clrscr( ) ;
gets ( expr ) ;
convert ( &p ) ;
show ( p ) ;
getch( ) ;
http://vujannat.ning.com/
p -> top = -1 ;
p -> s = "" ;
p -> s = str ;
else
{
http://vujannat.ning.com/
p -> top++ ;
if ( p -> top == -1 )
return -1 ;
else
p -> top-- ;
return item ;
char opr ;
while ( *( p -> s ) )
p -> s++ ;
continue ;
*( p -> t ) = *( p -> s ) ;
p -> s++ ;
p -> t++ ;
if ( *( p -> s ) == '(' )
push ( p, *( p -> s ) ) ;
p -> s++ ;
http://vujannat.ning.com/
if ( *( p -> s ) == '*' || *( p -> s ) == '+' || *( p -> s ) == '/' || *( p -> s ) == '%' || *( p -> s ) == '-' || *( p
-> s ) == '$' )
if ( p -> top != -1 )
opr = pop ( p ) ;
*( p -> t ) = opr ;
p -> t++ ;
opr = pop ( p ) ;
push ( p, opr ) ;
push ( p, *( p -> s ) ) ;
else
push ( p, *( p -> s ) ) ;
p -> s++ ;
if ( *( p -> s ) == ')' )
http://vujannat.ning.com/
opr = pop ( p ) ;
*( p -> t ) = opr ;
p -> t++ ;
opr = pop ( p ) ;
p -> s++ ;
*( p -> t ) = opr ;
p -> t++ ;
*( p -> t ) = '\0' ;
if ( c == '$' )
return 3 ;
return 2 ;
else
if ( c == '+' || c == '-' )
return 1 ;
else
return 0 ;
http://vujannat.ning.com/