Trading space against time, you could build two "Boolean" arrays indexed by temp->left->oper
and temp->left->oper
, respectively.
The corresponding array contains true when the condition is met, false otherwise.
So:
while (array1[temp->left->oper] || array1[temp->right->oper]) {
// do something
}
As the sets for left and right seem identical, one array will actually do.
Initialization would be like this:
static char array1[256]; // initialized to "all false"
...
array1['+'] = array1['-'] = array1['*'] = array1['/'] = '\001';
Similar for array2
.
As jumps are bad for modern pipelining CPUs, you could even use a larger table like this:
while (array1[temp->left->oper << 8 | temp->right->oper]) {
// do something
}
But initialization is more tricky:
static char array1[256 * 256]; // initialized to "all false"
...
void init(char c) {
for (unsigned char i = 0; i <= 255; ++i) {
array1[(c << 8) | i] = array1[(i << 8) | c] = '\001';
}
}
init('+');
init('-');
init('*');
init('/');