Click here to Skip to main content
15,888,143 members
Home / Discussions / C#
   

C#

 
GeneralRe: Streamwriter output Pin
Pete O'Hanlon15-Mar-11 23:48
mvePete O'Hanlon15-Mar-11 23:48 
GeneralRe: Streamwriter output Pin
Pierre besquent16-Mar-11 0:09
Pierre besquent16-Mar-11 0:09 
AnswerRe: Streamwriter output Pin
Luc Pattyn16-Mar-11 0:06
sitebuilderLuc Pattyn16-Mar-11 0:06 
GeneralRe: Streamwriter output Pin
Pierre besquent16-Mar-11 0:11
Pierre besquent16-Mar-11 0:11 
GeneralRe: Streamwriter output Pin
Pete O'Hanlon16-Mar-11 0:23
mvePete O'Hanlon16-Mar-11 0:23 
GeneralRe: Streamwriter output Pin
Luc Pattyn16-Mar-11 0:27
sitebuilderLuc Pattyn16-Mar-11 0:27 
GeneralRe: Streamwriter output Pin
Pierre besquent16-Mar-11 3:41
Pierre besquent16-Mar-11 3:41 
Questionbest data strcuture for numeric parsing. Pin
shivamkalra15-Mar-11 18:24
shivamkalra15-Mar-11 18:24 
Hi,

I've a assignment where I have to write a program that can parse and evaluate certain numerical expression like

sin(30)*5*log10(300)/6^2%5


Well, I've already done my research through reading articles on code project, there are very good examples on this topic. So I've decided to use STACK based infix to post-fix conversion and finally evaluating the post-fix expression again using stack.

Right Now, I've a class called "Expression" that stores each expression viz. *, /, %, sin, cos, log, tan..and many more. Let say you've following post fix expression

10 20 + 2 ^ sin 56 % 5 *


In simpler term, its infix expression is

(sin((10 + 20)^2) % 56) * 5


Now, during evaluating post fix expression, you encounter operators viz. *, /, ^, %, then you pop two elements from stack and perform this operation and finally you get result. I've like 30 of these mathematical operators, each time these operator occurs in post fix expression (operator is just a character in string), I perform search like

if(operator == '*')
{
return var1 * var2;
}

if(operator == '*')
{
return var1 * var2;
}

if(operator == '/')
{
return var1 / var2;
}

if(operator == '%')
{
return var1 % var2;
}
.
.
.
.
so on


Now this thing alone taking worst case of 30 matches for each of the operator within the post fix, so if post fix has 10 operators, it is gonna take 30*10 = 300 matches (worst case). I'm not able to think of any proper solution for preventing this problem. Currently, I'm thinking of making 30 classes for each of the operator and every class implementing "iExpression" interface, with method signature "evaluate (int var1, int var2)" that will perform specific function during run time without going through 30 if-else statements. But again making 30 classes is weird solution??

Can anybody please help, I would really appreciate it.

Regards,
Shivam Kalra
AnswerRe: best data strcuture for numeric parsing. Pin
GlobX15-Mar-11 19:27
GlobX15-Mar-11 19:27 
GeneralRe: best data strcuture for numeric parsing. Pin
shivamkalra15-Mar-11 20:22
shivamkalra15-Mar-11 20:22 
GeneralRe: best data strcuture for numeric parsing. Pin
GlobX15-Mar-11 20:32
GlobX15-Mar-11 20:32 
GeneralRe: best data strcuture for numeric parsing. Pin
shivamkalra15-Mar-11 20:37
shivamkalra15-Mar-11 20:37 
GeneralRe: best data strcuture for numeric parsing. Pin
GlobX15-Mar-11 20:53
GlobX15-Mar-11 20:53 
GeneralRe: best data strcuture for numeric parsing. Pin
shivamkalra15-Mar-11 20:33
shivamkalra15-Mar-11 20:33 
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 
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 

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.