Dsa.4 Code Output
Dsa.4 Code Output
Code:
#include<iostream>
#include<string.h>
struct node {
char data;
node *left;
node *right;
};
class tree {
public:
};
class stack1 {
public:
int top;
node *pop() {
return data[top--];
};
stack1 s;
int len, i;
len = strlen(prefix);
top->left = NULL;
top->right = NULL;
if (isalpha(prefix[i])) { // Operand
top->data = prefix[i];
s.push(top);
top->data = prefix[i];
top->right = t2;
s.push(top);
top = s.pop();
if (!top) {
return;
node *T = top;
s1.push(T);
while (!s1.empty()) {
T = s1.pop();
s2.push(T);
if (T->left) s1.push(T->left);
if (T->right) s1.push(T->right);
while (!s2.empty()) {
top = s2.pop();
deletion(node->left);
deletion(node->right);
delete node;
int main() {
tree t;
char exp1[20];
int ch;
do {
switch (ch) {
case 1:
t.expression(exp1);
break;
case 2:
t.display(t.top);
break;
case 3:
t.deletion(t.top);
break;
case 4:
break;
default:
break;
return 0;
}
Output:
1 -> Enter prefix expression
3 -> Deletion
4 -> Exit
3 -> Deletion
4 -> Exit
cd+
3 -> Deletion
4 -> Exit
cd+
3 -> Deletion
4 -> Exit
Deleting node: c
Deleting node: d
Deleting node: +
3 -> Deletion
4 -> Exit
Choose an option (1-4): 2
Tree is empty!
3 -> Deletion
4 -> Exit