#include<stdio.h>
#include<iostream.h>
using namespace std;
#define SIZE 10
// An expression tree node
struct et1
{
char value;
et1* left, *right;
};
typedef struct et1 et;
et stack[SIZE];
int top = -1;
void push(et *data){
if(top == SIZE-1)
printf("\nStack is Full!!! Insertion is not possible!!!");
else{
top++;
stack[top]->value = data->value;
printf("\nInsertion success!!!");
}
}
et* pop(){
if(top == -1)
printf("\nStack is Empty!!! Deletion is not possible!!!");
else{
printf("\nDeleted : %d", stack[top]->value);
top--;
return stack[top+1];
}
}
// A utility function to check if 'c'
// is an operator
bool isOperator(char c)
{
if (c == '+' || c == '-' ||
c == '*' || c == '/' ||
c == '^')
return true;
return false;
}
// Utility function to do inorder traversal
void inorder(et *t)
{
if(t)
{
inorder(t->left);
printf("%c ", t->value);
inorder(t->right);
}
}
// A utility function to create a new node
et* newNode(int v)
{
et *temp = new et;
temp->left = temp->right = NULL;
temp->value = v;
return temp;
};
// Returns root of constructed tree for given
// postfix expression
et* constructTree(char postfix[])
{
et *t, *t1, *t2;
// Traverse through every character of
// input expression
for (int i=0; i<strlen(postfix); i++)
{
// If operand, simply push into stack
if (!isOperator(postfix[i]))
{
t = newNode(postfix[i]);
push(t);
}
else // operator
{
t = newNode(postfix[i]);
// Pop two top nodes
t1 = pop(); // Store top
// Remove top
t2 = pop();
// make them children
t->right = t1;
t->left = t2;
// Add this subexpression to stack
push(t);
}
}
// only element will be root of expression
// tree
t = pop();
return t;
}
// Driver program to test above
int main()
{
char postfix[] = "ab+ef*g*-";
et* r = constructTree(postfix);
for(int i=0;i<10;i++)
{
et *temp=new stack[i];
stack[i]->value='/n';
stack[i]->left=NULL;
stack[i]->right=NULL;
}
printf("infix expression is \n");
inorder(r);
return 0;
}
(1) (50%) Write a C program that takes as input a fully parenthesized, arithmetic expression of...
Write a program that takes as input a fully parenthesized , arithmetic expression and convert it to a binary expression tree. Your program should display the tree in some way and also print the value associated with the root. LANGUAGE In java Please answer...
Write a simple java program that takes input from the user as a fully parenthesized expression and converts it to a binary tree. Ex: (1+2 * (6-4)) or (A+B / (D-C)) When the tree is built, it should print the tree in some way.
1. Write a program in C to show how to traverse a tree or visit each node in the tree exactly once? Use the following figure to implement the three methods, LVR (inorder), LRV (postorder), VLR (preorder). 17 1819 14 12 8 Figure 5.15: Binary tree with arithmetic expression
This is in Java Create a client class that does the following: Manually creates an instance of a binary expression tree that represents the following expression: (((5+2)*(2-1)/((2+9))+((7-2)-1))*8) Do this by using methods such as addRoot, addLeft, addRight, set, and attach. The element should be of type String Note that you are manually building this specific expression tree, the pseudo code might look something like: Create a LinkedBinaryTree Add “*” as the root to the tree Add “/” as the left...
write a new test program called RemoveDuplicates.java. The program reads text input from keyboard or a text file and adds the words to a BST. The program then traverses the BST and prints out the words in order (based on ASCII/UNICODE order) on the screen (or to output text file). Note that you may need to make some changes to BST.java. Sample test: ----jGRASP exec: java -ea removeDuplicates Original Text: a B 2 n w C q K l 0...
You are to write a program name expressionTree.java that evaluates an infix expression entered by the user. The expression may contain the following tokens: (1) Integer constants (a series of decimal digits). (2) One alphabetic character - "x" (representing a value to be supplied later). (3) Binary operators (+, -, *, / and % (modulo)). (4) Parentheses You will parse the input expression creating an expression tree with the tokens, then use the postOrder tree traversal algorithm to extract...
Please I need help ASAP Java Programing: Binary Search Tree Fully implement the BST class in Listing 25.4 (on page 961 of the 11th Edition of the text). Design and write a (main) driver program to completely test every method in the BST class to ensure the class meets all its requirements. You should read the Listing 25.5: TestBST.java for an idea of what your program should look like. Listing 25.4 BST.java public class BST> extends AbstractTree { protected TreeNode...
Write a C++ program that reads string expressions from an input file "prefix.txt" containing prefix expressions (one expression per input line). For each prefix expression read from the input file, the program should: (1) convert the expression to a fully parenthesized infix expression and (2) find the value of the expression. Use a stack to solve the problem. Assume the expressions contain only integer numbers and the *,/, +, - operators. Generate the results in an output file "results.txt" in...
Objective To acquire expertise in stack manipulation and management, subroutine linkage and return conventions, and recursive procedures. Description You are to create a MIPS programming assignment that returns postfix representation of the input and create an expression tree. Your MIPS program should make use of the expression tree to store the input and provide, by means of an adequate traversal, the value for the expression. Your solution should be structured according to the following steps: Step 1: Convert expression from...
Question: Write a Java program for Evaluating Postfix Expression 1. Input a postfix expression from user. 2. Evaluate expression using double stack made of your own linked list. 3. Show the result of expression or error if incorrect. Evaluating Postfix Expression Input an expression: 2 10 + 9 6 - / Evaluating Postfix Expression Input an expression: 20 10 + 9 6 - 1 Evaluating Postfix Expression Input an expression: 2 10 + 9 - / Result = 4.0 Result...