Click here to Skip to main content
16,005,178 members
Home / Discussions / C#
   

C#

 
GeneralRe: calculator Pin
the exile26-Mar-09 8:20
the exile26-Mar-09 8:20 
GeneralRe: calculator Pin
EliottA26-Mar-09 8:48
EliottA26-Mar-09 8:48 
QuestionRe: calculator Pin
CPallini26-Mar-09 8:09
mveCPallini26-Mar-09 8:09 
JokeRe: calculator Pin
Yusuf26-Mar-09 8:50
Yusuf26-Mar-09 8:50 
JokeRe: calculator Pin
CPallini26-Mar-09 9:04
mveCPallini26-Mar-09 9:04 
JokeRe: calculator Pin
0x3c026-Mar-09 9:35
0x3c026-Mar-09 9:35 
AnswerRe: calculator Pin
Roger Wright26-Mar-09 20:04
professionalRoger Wright26-Mar-09 20:04 
AnswerRe: calculator [modified] Pin
Alan Balkany27-Mar-09 3:59
Alan Balkany27-Mar-09 3:59 
Here's how I would do this:

1. Make a binary tree. Leaf nodes stand for your variables (A, B, f, g...). Interior nodes stand for an operation on the values of the interior node's two sons.

2. Go through your statement and put all tokens into a list of leaf nodes. (The operations will eventually be transferred to interior nodes.)

3. Find the range of nodes where the parentheses are most deeply nested.

4. If you have the pattern [left parenthesis] [variable] [right parenthesis], delete the two parentheses nodes. (The variable could also be an interior node.)

5. In this deeply-nested region, replace the pattern [variable] [high-precedence-operation] [variable] with an interior node for the operation, with the two variables as sons. (The variables could also be other interior nodes.)

6. Repeat Step 5 for the low-precedence operations. You should now be able to apply Step 4 on the remaining interior node left in the parentheses.

7. To evaluate the expression, do a post-order traversal on the binary tree, getting the variable values for leaf nodes, and applying the operation to the two values for interior nodes. The result of the evaluation will be left in your root node.

I find this approach simpler than the recursive algorithms.

modified on Friday, March 27, 2009 10:10 AM

Questionhow to use a list array to populate a listbox with columns Pin
robertkjr3d26-Mar-09 7:31
robertkjr3d26-Mar-09 7:31 
AnswerRe: how to use a list array to populate a listbox with columns Pin
dan!sh 26-Mar-09 7:44
professional dan!sh 26-Mar-09 7:44 
GeneralRe: how to use a list array to populate a listbox with columns Pin
robertkjr3d26-Mar-09 7:57
robertkjr3d26-Mar-09 7:57 
GeneralRe: how to use a list array to populate a listbox with columns Pin
dan!sh 26-Mar-09 8:15
professional dan!sh 26-Mar-09 8:15 
GeneralRe: how to use a list array to populate a listbox with columns Pin
robertkjr3d26-Mar-09 8:25
robertkjr3d26-Mar-09 8:25 
GeneralRe: how to use a list array to populate a listbox with columns Pin
Fayu26-Mar-09 8:39
Fayu26-Mar-09 8:39 
GeneralRe: how to use a list array to populate a listbox with columns Pin
dan!sh 26-Mar-09 8:48
professional dan!sh 26-Mar-09 8:48 
AnswerRe: how to use a list array to populate a listbox with columns Pin
Fayu26-Mar-09 8:00
Fayu26-Mar-09 8:00 
GeneralRe: how to use a list array to populate a listbox with columns Pin
robertkjr3d26-Mar-09 8:08
robertkjr3d26-Mar-09 8:08 
GeneralRe: how to use a list array to populate a listbox with columns Pin
Fayu26-Mar-09 8:37
Fayu26-Mar-09 8:37 
GeneralRe: how to use a list array to populate a listbox with columns Pin
robertkjr3d26-Mar-09 8:43
robertkjr3d26-Mar-09 8:43 
GeneralRe: how to use a list array to populate a listbox with columns Pin
Henry Minute26-Mar-09 10:39
Henry Minute26-Mar-09 10:39 
QuestionEmbed a progress bar inside a treeview node Pin
JamieNS26-Mar-09 7:30
JamieNS26-Mar-09 7:30 
AnswerRe: Embed a progress bar inside a treeview node Pin
dan!sh 26-Mar-09 7:55
professional dan!sh 26-Mar-09 7:55 
QuestionArgument Exception appears in some computers but not in others Pin
VitroBlue26-Mar-09 7:15
VitroBlue26-Mar-09 7:15 
AnswerRe: Argument Exception appears in some computers but not in others Pin
Luc Pattyn26-Mar-09 8:44
sitebuilderLuc Pattyn26-Mar-09 8:44 
QuestionSend data to USB ? Pin
Mohammad Dayyan26-Mar-09 7:00
Mohammad Dayyan26-Mar-09 7:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.