Ok, i understand that posting the whole code is really hard to read. SO i chose the most critical part. It's the actual function to convert form infix notation to postfix notation. BUt there are other functions i wrote used in this function, just assume they're fine and correct right now. Pls hav a look at the following function and see if there are any logic erros and stuff. If you forgot the algorithm, it's in the first thread.
thnx in advance
Code:
void convertToPostfix( char infix[], char postfix[] )
{
StackNodePtr topPtr = NULL;
int arraySize, infixCounter = 0, postfixCounter = 0;
char popValue;
int i;
push( &topPtr, '(' );
arraySize = strlen( infix );
infix[ arraySize + 1 ] = ')';
infix[ arraySize + 2 ] = '\0';
while ( isEmpty( topPtr ) != 1 ) {
if ( isdigit( infix[ infixCounter ] ) ) {
postfix[ postfixCounter ] = infix[ infixCounter ];
infixCounter++;
postfixCounter++;
}
else if ( infix[ infixCounter ] == '(' ) {
push( &topPtr, infix[ infixCounter ] );
infixCounter++;
}
else if ( isOperator( infix[ infixCounter ] ) ) {
while ( precedence( stackTop( topPtr ), infix[ infixCounter ] ) == 1 ||
precedence( stackTop( topPtr ), infix[ infixCounter ] ) == 0 ) {
popValue = pop( &topPtr );
postfix[ postfixCounter ] = popValue;
postfixCounter++;
}
push( &topPtr, infix[ infixCounter ] );
infixCounter++;
}
else if ( infix[ infixCounter ] == ')' ) {
while ( stackTop( topPtr ) != '(' ) {
popValue = pop( &topPtr );
postfix[ postfixCounter ] = popValue;
postfixCounter++;
}
pop( &topPtr );
infixCounter++;
}
}
postfix[ postfixCounter ] = '\0';
}