Transform the Expression - WA

c
c-plus-plus
data-structure

#1

#include <stdio.h>
#include <ctype.h>

int main()
{
int t;
scanf("%d", &t);

while(t--)
{
    char expression[400];
    expression[0] = '\0';

    scanf("%s", expression);

    char operatorStack[400];
    operatorStack[0] = '\0';
    int operatorStackLength = 0;
    char operandStack[400];
    operandStack[0] = '\0';
    int operandStackLength = 0;

    int i;

    for(i = 0; expression* != '\0'; i++)
    {
        if(isalpha(expression*))
        {
            operandStack[operandStackLength++] = expression*;
        }
        else if(expression* == '(')
        {
            operatorStack[operatorStackLength++] = expression*;
        }
        else if(expression* == ')')
        {
            operatorStackLength--;
            while(operatorStack[operatorStackLength] != '(')
            {
                operandStack[operandStackLength] =  operatorStack[operatorStackLength];
                operandStackLength++;
                operatorStackLength--;
            }
        }
        else
        {
            operatorStack[operatorStackLength++] = expression*;
        }
    }

    printf("%s

", operandStack);
}

return 0;

}


#2

test your program with ‘a+bc’, its showing ‘abc’ instead of 'abc+’


#3

So we have to consider without bracket case only if there if one operand in the whole expression??


#4

Thanks man that was the only problem :0