MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / compute

Function compute

CPP/Trees/Expression_tree/BST.c:151–171  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

149}
150
151int compute(EXT tree) {
152 if(tree == NULL)
153 return 0;
154
155 if(tree->left == NULL && tree->right == NULL)
156 return ((int)tree->data) - 48;
157
158 int left = compute(tree->left);
159 int right = compute(tree->right);
160
161 if(tree->data == '+')
162 return left + right;
163 if(tree->data == '-')
164 return left - right;
165 if(tree->data == '*')
166 return left * right;
167 if(tree->data == '/')
168 return left / right;
169
170 return -1;
171}
172
173

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected