Creating a Linked List of Char
i have a program that computes a stack in linked list for numbers, and i was wondering if it could be done the same for characters.
@wio
for numbers? what do you mean?
nvm, i got that one, but i'm stuck with another one. i am trying to convert Infix expression in to Postfix expression but my code is not changing it, can you see the code and see what i did wrong?
I don't know what you are trying to do or what language you are using.
im using C++, and tying to convert Infix Expression to Postfix expression
operation overriding?
yes
You put (int) as an argument and don't use it, that will change it to postfix.
can you clarify it more? also i can't use libraries
In order to change the function signature so it overloads postfix instead of prefix, you need to have to give it an int parameter.
sorry, but what did you mean by operation overriding?
Making it so that you can use operations like +, ++, -, etc. on objects of a class that has defined their behavior.
the struct is for the stack
What is the problem?
it doesn't crash or anything, it runs so basically, the program asks the user to input "Infix expression", and it is suppose to convert it to "postfix", but it doesn't convert it; it gives me back the "Infix expression" instead of the "postfix"
what are examples of input?
Your code doesn't even compile.
it can be anytype of expressions like for example: 5+9/5-1*23 something like that
it should, hold on let me check it again
also, you didn't even indent it properly.
take out the return value on "void pop" and it should compile
will it have an effect on the code for not being indented properly?
No, when it isn't indented properly, my willingness to help shrinks considerably.
Why should this code even work?
when i paste it to notepad, the lines went out of control
Code has no comments and is hard to read. I have no idea what it is supposed to actually be doing. What do you expect the output to be?
It's okay, i'll try to fix it up tomorrow. Thanks for your time
Here is what you need to do. Create a function which prints our what is in your stack. Then print out your stack after each loop.
okay
Good news is that your stack is working at the very least. Bad news is it is always empty in your code.
I moved the ``` while (!empty()){ convertpost += topy(); pop(); } ``` To be outside of the for loop, and got `59+5/1-23*` for output
``` int highpress (char a){ int worth = -1; switch (a){ case '+': case '-': worth = 1; break; case '*': case '/': worth = 2; break; case '(': case ')': worth = 3; break; case '$': worth = 4; } return worth; } ``` Putting break statements in your switch statement got output of `595/+123*-`
moving the the "while"outside the "for loop" worked :) Thanks a lot
Join our real-time social learning platform and learn together with your friends!