this is not correct. which platform you are working on??
i think you never debug your program.. the code which i send you, you are using it incorrectly.
when you send it A or B it returns you either A or B whose prec is higher. but in your code you are using it like this:
while(!P.isEmpty() && (presidence(infix[i],P.stackTop())))
you are not saving the return value of presidence, how will you know what the function is returning..
my first suggestion is dont use '(' and ')'. first make your minimum program working and then give it more features. ok? starting with a complex program is not good idea.
so remove this feature from your first working version if you like this advise.
now what you have to do is:
modify the return type of presidence function to bool, now it will be like this:
if(presidence(a, b)) this will return true if a is greater presidence else false.
then what you can do is:
1 2 3 4 5 6 7 8 9 10
|
if(presidence(input, instack))
{
//input has greater presidence so put input operator in the postfix array
}
else
{
//input has less presidence
//pop the operator stack, put the popped character in the postfix array
//and put the input operator in the operator stack. correct?
}
|
give it a try then i will help you. i hope you are getting what i mean??
just make a small program, dont try too many features with it or you will be drowned in the complexity.
:)