15,390,011 members
See more:
``` the student should implement in C language the infix-to-postfix conversion algorithm given below:
Read input string to an empty buffer (we assume a valid string is provided)
Place a marker to the first symbol of the input
While marker is not pointing to the end of the input string, do (discard white-space characters, if exist)
If marker points to an operand, then
Place it to the output string
Else-if marker points to an opening parenthesis, then
Push it to the operator’s stack
Else-if marker points to an operator, then
If operator’s stack is empty, then
Push it to the operator’s stack
Else-if top of the operator’s stack is an opening parenthesis, then
Push it to the operator’s stack
Else-if operator has higher priority than operator at the top of the operator’s stack, then
Push it to the operator’s stack
Else
While operator’s stack is not empty and
top of the operator’s stack is not an opening parenthesis or is an operator that has same or higher priority, do
Pop an operator from the operator’s stack
Place it to the output string
End-while
Push operator to the operator’s stack
End-if
Else-if marker points to a closing parenthesis, then
While top of the operator’s stack is not an opening parenthesis, do
Pop an operator from the operator’s stack
Place it to the output string
End-while
Pop and discard the opening parenthesis
End-if
Advance marker to the next symbol
End-while
If operator’s stack is not empty, then
While operator’s stack is not empty, do
Pop an operator from the operator’s stack
Place it to the output string
End-while
End-if
Print output string
Note that you should translate the pseudocode one-to-one into C statements.```

What I have tried:

Posted
Updated 21-Nov-20 10:30am
Rick York 21-Nov-20 12:50pm

## Solution 1

Quote:

Not even the slightest effort to solve the problem by yourself, pity.

You show no attempt to solve the problem yourself, you have no question, your main effort is pasting the requirement, you just want us to do your HomeWork.
HomeWork problems are simplified versions of the kind of problems you will have to solve in real life, their purpose is learning and practicing.

We do not do your HomeWork.
HomeWork is not set to test your skills at begging other people to do your work, it is set to make you think and to help your teacher to check your understanding of the courses you have taken and also the problems you have at applying them.
Any failure of you will help you to learn what works and what don't, it is called 'trial and error' learning.
So, give it a try, reread your lessons and start working. If you are stuck on a specific problem, show your code and explain this exact problem, we might help.

## Solution 2

We are more than willing to help those that are stuck: but that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]

## Solution 3

The first thing you need to do is implement an operator stack. Traditionally, stacks have values pushed onto them and popped off of them. Your stack needs to do the same things. Essentially a stack is a linked list with a top marker and a pointer to a next item.

Pushing a value means you have a new top element and the old top is the new one's next item.

Popping means the old top item is returned and it's next item is now the top item of the stack.

That's all there is to it. To add an item means allocate space for a stack item which will be a structure containing a data item and a pointer to the next item. You can use alloc or calloc to allocate memory. When popping, you should return the data item and release the item's memory using free. This site provides a useful language reference: cplusplus.com - The C++ Resources Network[^].

Yes, I know this is more pseudo code but a programming course is meant to teach programming. You need to actually write code to learn how to do it. Having others write code for you teaches nothing.

Top Experts
Last 24hrsThis month
 Richard MacCutchan 125 OriginalGriff 95 0x01AA 75 Gerry Schmitz 55 Patrice T 45
 OriginalGriff 990 Richard MacCutchan 515 0x01AA 265 Gerry Schmitz 250 Maciej Los 195

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900