You really have to give a lot more information in order to enable me to help you. However, by wild guessing, I am trying to nudge you into the right direction.
I assume you are trying to program a simple + - * / = infix calculator with or without a graphical user interface.
To get operators and operator precedence right, it is a good idea to create to a data structure of type stack. Stacks are abstract containers with operations push(), pop() and isempty().
A nice-to-have convenience extra is an operation top(). It returns the topmost stack element without removing it (you can emulate by a pop(); push() sequence at some performance costs, so its not a strict requirement for a stack).
only
Stacks are LIFO memories, Last In, First Out, so what you push most recently will get returned by pop first. Just like a stack of cards where you can put a new card only to the top and take away from the top, too.
Processing of the input is done according to the "Shunting-Yard Algorithm", invented by Edsger Wybe Dijkstra. The link directs you to the Wikipedia page of the algorithm, which does an extensive discussion, much nicer than what I could do here on FixYa.
188 views
Usually answered in minutes!
×