Tree data structure in Objective C

data-structures expression-trees objective-c

Question

I need to implement a Tree data structure in Objective C and figure out how it works.

So what I know right now:

About - how it looks.

Tree is a recursive data structure. There are few parameters that I have to to implement, for example without methods for add, search, delete and other:

id info;
id left_node;
id right_node;

As I understand info - is a value that each node stores (e.g. NSInteger, NSString or something else). left_node and right_node there are pointers to other nodes in current tree or subtree.

About add to tree

For example I need to add next data that based on expression below:

50*(10-(5+6)) + (60*(10-2))

So on this step I have a problem, because I don't now how it will looks in tree and I need help with this.

1
0
9/20/2012 1:40:35 PM

Accepted Answer

I'v googled for you:

enter image description here

this is (4*3)+((2*7)-5)

so info must be a class that is something like

bool isOperation;
NSInteger number;
NSInteger operation idx;   //like 0 for '+', 1 for '-' ecc. to evaluate in a case
0
9/20/2012 3:06:44 PM


Related Questions





Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow