Hi!
is there any way to eliminate some of these if else statements [without using goto and labels] in the following piece of code
there are several ways i can re-arrange these, checking with negation (!), but i always end up with two pairs of if-else. it seems like i could eliminate one of them since in two cases i have the same output.... is it possible?
thanks.
p.s. s is a Stack object. Stack class implemented with Nodes, but of course that has no bearing with the case.
Avendeval Sedai
[sub]yavoor@yahoo.com[/sub]
is there any way to eliminate some of these if else statements [without using goto and labels] in the following piece of code
Code:
//.....other code
if(s.getType()==Node::INT){
i = s.pop();
if(!s.empty()){
cerr << "ERROR: Invalid prefix format [too many operators?] in line "
<< count
<< ".\nIgnoring line.\n";
s.flush();
}
else
cout << "Line " << count << " Result: " << i << endl;
}
else{
cerr << "ERROR: Invalid prefix format [too many operators?] in line "
<< count
<< ".\nIgnoring line.\n";
s.flush();
}
there are several ways i can re-arrange these, checking with negation (!), but i always end up with two pairs of if-else. it seems like i could eliminate one of them since in two cases i have the same output.... is it possible?
thanks.
p.s. s is a Stack object. Stack class implemented with Nodes, but of course that has no bearing with the case.
Avendeval Sedai
[sub]yavoor@yahoo.com[/sub]