Employeeinformation Using Postorder
Employeeinformation Using Postorder
if (isOperator(ch)) {
if (st.size() < 2) {
cerr << "Invalid prefix expression.\n";
exit(1);
}
node->left = st.top(); st.pop();
node->right = st.top(); st.pop();
}
st.push(node);
}
if (st.size() != 1) {
cerr << "Invalid prefix expression.\n";
exit(1);
}
return st.top();
}
while (!s1.empty()) {
Node* curr = s1.top(); s1.pop();
s2.push(curr);
if (curr->left) s1.push(curr->left);
if (curr->right) s1.push(curr->right);
}
int main() {
string prefix;
cout << "Enter a prefix expression (e.g., +--a*bc/def): ";
cin >> prefix;
return 0;
}