Ds Practical 3
Ds Practical 3
Q. For given expression eg. a-b*c-d/e+f construct inorder sequence and traverse
it using postorder traversal (non recursive)
#include <iostream>
#include <stack>
#include <string>
class Node {
public:
char data;
Node* left;
Node* right;
Node(char val) {
data = val;
};
bool isOperator(char c) {
stack<Node*> st;
if (isspace(ch)) continue;
if (!isOperator(ch)) {
st.push(new Node(ch));
} else {
st.push(node);
return st.top();
inorder(root->left);
inorder(root->right);
s1.push(root);
while (!s1.empty()) {
s2.push(curr);
if (curr->left) s1.push(curr->left);
if (curr->right) s1.push(curr->right);
while (!s2.empty()) {
s2.pop();
int main() {
inorder(root);
postorderNonRecursive(root);
return 0;
Output:-