Wednesday, January 8, 2014

Continuous evaluation of expression issues

According to the book's examples implements a calculator, but how to achieve such a +2 * 4 consecutive evaluated it?
Reply:
With [nsstring compont seperatebystring: @ "+"] approach record count
With [nsstring compont seperatebystring: @ "-"] method
With [nsstring compont seperatebystring: @ "*"] method
With [nsstring compont seperatebystring: @ "/"] method

Separation of the string to form a new array

Then remove from the array corresponding figures for computing. . .

I can only think of death method. . . Inflect not thought. . . Also want to have an expert pointing. . .
Reply:
Need to understand the algorithm
Optional stack structure to do.
Reply:

NSString * result = [[[[UIWebView alloc] init] autorelease] stringByEvaluatingJavaScriptFromString: @ "1 +2 * 4"];

If there is no algorithm-based (need to consider recursion, backtracking, etc.), the inflection point, you can directly call the JS.
Reply:
Expressions algorithm which is based on algorithms to buy some of the basic algorithm to translate the book looked over. . .
Reply:
reference to the third floor zhangao0086 reply:
NSString * result = [[[[UIWebView alloc] init] autorelease] stringByEvaluatingJavaScriptFromString: @ "1 +2 * 4" ];

If there is no algorithm-based (need to consider recursion, backtracking, etc.), the inflection point, you can directly call the JS.

The original value but also so ah
Reply:
With NSString * result = [[[[UIWebView alloc] init] autorelease] stringByEvaluatingJavaScriptFromString: @ "2 ^ 2"]; 2 square when not count, as if the ^ number as the - No.
Reply:
Taught

No comments:

Post a Comment