Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
my own calculator
#6
They could be very helpful. But this is still possible by removing all the whitespace and going through the infix expression one character at a time. If you find an operand, you throw it at the end of your prefix expression string. If it's an open parenthesis, you push it on the stack. When you find an operator, you push it on the stack if the stack is empty...if it's not empty, you pop every operator of greater or equal precedence (stop when an operator of lower precedence is found, another open parenthesis is found, or the stack is empty) and throw them onto the end of your prefix string...and THEN you can push your operator on the stack. If you find the close parenthesis, you just pop the operators off the stack until you find its matching open parenthesis. Finally, if you hit the end of the infix expression, you just pop everything off the stack and throw it at the end of your prefix string. But that's just converting infix notation to prefix notation using a stack. The fun part comes when you evaluate the expression. Now that your expression is in prefix notation, it should be easier to evaluate it using whatever algorithm you come up with. One last thing, you don't necessarily have to use stacks, there are quite a few ways of accomplishing this...and it may have been a mouth full, so I could try to explain this by writing pseudocode if needed. There are a lot of resources on this topic, too.
<Aoi-chan> everyone's first vi session. ^C^C^X^X^X^XquitqQ!qdammit[esc]qwertyuiopasdfghjkl;:xwhat
Reply


Messages In This Thread
my own calculator - by WHITE PANDA - 05-24-2010, 02:43 AM
RE: my own calculator - by delme - 05-24-2010, 03:38 AM
RE: my own calculator - by WHITE PANDA - 05-28-2010, 06:58 AM
RE: my own calculator - by Psycho - 06-02-2010, 01:17 PM
RE: my own calculator - by MrD. - 06-02-2010, 04:40 PM
RE: my own calculator - by Psycho - 06-02-2010, 10:08 PM
RE: my own calculator - by Zerk.Gamer.Coder - 06-18-2010, 08:53 AM
RE: my own calculator - by iHood - 06-18-2010, 08:55 AM
RE: my own calculator - by Kondry - 07-14-2010, 03:19 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Multi Purpose Calculator Reality 21 5,084 12-14-2010, 06:11 PM
Last Post: Buzz Lightyear
  Calculator v1 Brainless Control 21 5,220 01-18-2010, 10:34 PM
Last Post: Equinøx
  Calculator in C Liberty 4 1,318 12-10-2009, 11:45 PM
Last Post: Sagittarius

Forum Jump:


Users browsing this thread: 1 Guest(s)