Click here to Skip to main content
15,922,696 members
Home / Discussions / C#
   

C#

 
AnswerRe: best data strcuture for numeric parsing. Pin
_Maxxx_15-Mar-11 19:43
professional_Maxxx_15-Mar-11 19:43 
QuestionRe: best data strcuture for numeric parsing. Pin
GlobX15-Mar-11 19:58
GlobX15-Mar-11 19:58 
AnswerRe: best data strcuture for numeric parsing. Pin
shivamkalra15-Mar-11 20:23
shivamkalra15-Mar-11 20:23 
GeneralRe: best data strcuture for numeric parsing. Pin
shivamkalra15-Mar-11 20:25
shivamkalra15-Mar-11 20:25 
AnswerRe: best data strcuture for numeric parsing. Pin
PIEBALDconsult16-Mar-11 2:56
mvePIEBALDconsult16-Mar-11 2:56 
AnswerRe: best data strcuture for numeric parsing. Pin
_Erik_16-Mar-11 3:44
_Erik_16-Mar-11 3:44 
GeneralRe: best data strcuture for numeric parsing. Pin
shivamkalra16-Mar-11 8:01
shivamkalra16-Mar-11 8:01 
AnswerRe: best data strcuture for numeric parsing. Pin
Alan Balkany16-Mar-11 4:27
Alan Balkany16-Mar-11 4:27 
I've used a much simpler approach to do this. The basic idea is you build a binary tree that represents your expression, where you have an interior node for each operator and its left and right sons are the operands.

1. Replace each token in your expression with a node that has left/right pointers, so it can be in a binary tree. Each number, operator, and parenthesis is a separate node. Initially the nodes are in a linear list, in the same order they appear in the expression.

2. We process the list, moving operand nodes to the left/right sons of operator nodes (or removing nodes) at each step, until we're left with a single node in the list: The root of the binary tree.

3. There are three operations:
a) If you have a single node enclosed by parentheses, eliminate the parentheses: (N) => N
b) Find the region most deeply nested in parentheses. Go through the nodes, moving the operands around the highest-precedence operators to the left/right sons: A + B * C + D => A + [* node with sons B and C] + D (Hard to draw a tree here...)
c) Go through this region again, this time doing the same operation to the next-lower-precedence operators:
        [+ node]
       /        \
  [+ node]       D
 /        \
A       [* node]
       /        \
      B          C


When done, only the root [+ node] will remain in the list. To evaluate, call the Eval() method on the root. Eval returns the value of the node's operand, or for an operator, it returns the operator applied to the Eval() of its sons.

It works, and it's way simpler than the standard approach.
AnswerRe: best data strcuture for numeric parsing. Pin
David198716-Mar-11 4:57
David198716-Mar-11 4:57 
QuestionObtaining Administrator Authority Pin
gmhanna15-Mar-11 17:21
gmhanna15-Mar-11 17:21 
AnswerRe: Obtaining Administrator Authority Pin
Dave Kreskowiak15-Mar-11 17:43
mveDave Kreskowiak15-Mar-11 17:43 
AnswerRe: Obtaining Administrator Authority Pin
DaveyM6916-Mar-11 2:15
professionalDaveyM6916-Mar-11 2:15 
AnswerRe: Obtaining Administrator Authority Pin
PIEBALDconsult16-Mar-11 17:03
mvePIEBALDconsult16-Mar-11 17:03 
Questioncpu performance with wmi ... Pin
SungBae.Han15-Mar-11 13:19
SungBae.Han15-Mar-11 13:19 
AnswerAppend information... Pin
SungBae.Han15-Mar-11 13:29
SungBae.Han15-Mar-11 13:29 
AnswerRe: cpu performance with wmi ... Pin
Valery Possoz23-Mar-11 12:54
professionalValery Possoz23-Mar-11 12:54 
QuestionIs there anything built in for distributed applications? Pin
SledgeHammer0115-Mar-11 11:31
SledgeHammer0115-Mar-11 11:31 
AnswerRe: Is there anything built in for distributed applications? Pin
Mycroft Holmes15-Mar-11 12:32
professionalMycroft Holmes15-Mar-11 12:32 
GeneralRe: Is there anything built in for distributed applications? Pin
SledgeHammer0115-Mar-11 12:44
SledgeHammer0115-Mar-11 12:44 
GeneralRe: Is there anything built in for distributed applications? Pin
Mycroft Holmes15-Mar-11 14:09
professionalMycroft Holmes15-Mar-11 14:09 
GeneralRe: Is there anything built in for distributed applications? Pin
SledgeHammer0115-Mar-11 14:24
SledgeHammer0115-Mar-11 14:24 
AnswerIt's Similar with my case. Pin
SungBae.Han15-Mar-11 13:16
SungBae.Han15-Mar-11 13:16 
AnswerRe: Is there anything built in for distributed applications? Pin
Albert Holguin15-Mar-11 13:31
professionalAlbert Holguin15-Mar-11 13:31 
AnswerRe: Is there anything built in for distributed applications? Pin
GlobX15-Mar-11 20:01
GlobX15-Mar-11 20:01 
Question_msize() on managed data arrays? Pin
Chesnokov Yuriy15-Mar-11 8:38
professionalChesnokov Yuriy15-Mar-11 8:38 

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.