Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int convertToPostfix( char *pszInfix, Out out )
- {
- Stack stack = newStack();
- Element element;
- Element popped;
- int bLeft = TRUE;
- pszInfix = getToken( pszInfix, element.szToken , MAX_TOKEN );
- while( pszInfix != NULL )
- {
- categorize( &element );
- switch( element.iCategory )
- {
- //case for '(' character
- case 1:
- push( stack, element );
- //case for ')' character
- case 2:
- while( isEmpty( stack ) == FALSE )
- {
- popped = pop( stack );
- if( strcmp( popped.szToken, "(" ) == TRUE )
- {
- bLeft == TRUE;
- break;
- }
- addOut( out, popped );
- }
- if( bLeft == FALSE )
- errExit( "Missing '('" );
- //case for '=, NEVER, ONLY, AND, OR'
- case 3:
- while( isEmpty( stack ) == FALSE )
- {
- popped = topElement( stack );
- if( element.iPrecedence > popped.iPrecedence )
- break;
- addOut( out, pop( stack ) );
- }
- push( stack, element );
- //case for operands
- case 4:
- addOut( out, element );
- }
- pszInfix = getToken( pszInfix, element.szToken , MAX_TOKEN );
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement