Professional Documents
Culture Documents
2 Adsl
2 Adsl
2 Adsl
- 22230143 A
ASSIGNMENT 2 ADSL
a) Construct binary tree using prefix expression and perform recursive inorder and
postorder traversal of a tree.
CODE:
#include <iostream>
using namespace std;
struct Node {
char data;
Node* left;
Node* right;
};
if (isalnum(symbol)) {
return newNode;
}
return newNode;
}
Name- Soham Kawadkar Div: SY-9 Roll no.- 22230143 A
int main() {
string prefix = "*+AB-CD";
int index = 0;
Node* root = constructTreeFromPrefix(prefix, index);
return 0;
}
OUTPUT:
Name- Soham Kawadkar Div: SY-9 Roll no.- 22230143 A
b) Construct binary tree using prefix expression and perform non-recursive inorder and
postorder traversal of a tree.
CODE:
#include <iostream>
#include <stack>
using namespace std;
struct Node {
char data;
Node* left;
Node* right;
};
if (isalnum(symbol)) {
return newNode;
}
return newNode;
}
Name- Soham Kawadkar Div: SY-9 Roll no.- 22230143 A
current = s.top();
s.pop();
current = current->right;
}
}
if (current->left) {
s1.push(current->left);
}
if (current->right) {
s1.push(current->right);
}
}
while (!s2.empty()) {
cout << s2.top()->data << " ";
s2.pop();
}
Name- Soham Kawadkar Div: SY-9 Roll no.- 22230143 A
int main() {
string prefix = "*+AB-CD";
int index = 0;
Node* root = constructTreeFromPrefix(prefix, index);
return 0;
}
OUTPUT:
Name- Soham Kawadkar Div: SY-9 Roll no.- 22230143 A
c) Construct binary tree using Postfix expression and perform recursive inorder & preorder
traversal.
CODE:
#include <iostream>
using namespace std;
struct Node {
char data;
Node* left;
Node* right;
};
if (isalnum(symbol)) {
return newNode;
}
return newNode;
}
Name- Soham Kawadkar Div: SY-9 Roll no.- 22230143 A
int main() {
string postfix = "AB+CD-*";
int index = postfix.size() - 1;
Node* root = constructTreeFromPostfix(postfix, index);
return 0;
}
OUTPUT:
Name- Soham Kawadkar Div: SY-9 Roll no.- 22230143 A
FAQs:
Name- Soham Kawadkar Div: SY-9 Roll no.- 22230143 A
Name- Soham Kawadkar Div: SY-9 Roll no.- 22230143 A