Infix to Postfix using stack

后端 未结 2 1236
走了就别回头了
走了就别回头了 2021-01-22 02:28

My lecturer gave me an assignment to create a program to convert an infix expression to postfix using Stack. I\'ve made the stack classes and some functions to read the infix ex

2条回答
  •  天涯浪人
    2021-01-22 03:20

    You really should learn how to use a debugger, it's a great tool for figuring out problems like these. However, I ran it and figured out your problem:

    On this line:

    while(precedence(list->top->data)<=precedence(string[i])){
    

    When you're iterating through the list, you need to check whether the stack is empty each time, not only before you go into the loop. So, do something like this:

    while(!isEmpty(list) && precedence(list->top->data)<=precedence(string[i])){
    

    instead.

提交回复
热议问题