Data Structure
Lecture No. 14
Binary Expression Tree
Engr. Rashid Farid Chishti
http://youtube.com/rfchishti
http://sites.google.com/site/chishti
International Islamic University H-10, Islamabad, Pakistan
Video Lecture
 Expression trees are binary trees for mathematical expression
 Leaves are operands (a, b, c, …)
 Other nodes are operators. (+, -, *, /)
 This is Expression Tree for
(a+b*c)+((d*e+f)*g)
Binary Expression Tree
+
+
*
b
a
c
*
+ g
f
*
d e
 Preorder traversal: (node, left, right) gives Prefix Expression.
+ + a * b c * + * d e f g
Expression Tree Traversal
+
+
*
b
a
c
*
+ g
f
*
d e
 Inorder traversal: (left, node, right) gives Infix Expression.
a + b * c + d * e + f * g
Expression Tree Traversal
+
+
*
b
a
c
*
+ g
f
*
d e
 Postorder traversal: (left, right, node) gives Postfix Expression.
a b c * + d e * f + g * +
Expression Tree Traversal
+
+
*
b
a
c
*
+ g
f
*
d e
 Read expression one symbol at a time
 If the symbol is an operand
 Create a one-node tree
 Push its pointer to a stack
 If the symbol is an operator
 Pop two pointers
 Form a new tree whose root is the operator
 In the end, the only element of the stack will be the root of an expression tree.
Constructing a Binary Expression Tree from Postfix
 a b + c d e + * *
Constructing Expression Tree from Postfix
Stack
 a b + c d e + * *
Constructing Expression Tree from Postfix
Stack
a
 a b + c d e + * *
Constructing Expression Tree from Postfix
Stack
a b
 a b + c d e + * *
Constructing Expression Tree from Postfix
Stack
b
+
a
 a b + c d e + * *
Constructing Expression Tree from Postfix
Stack
b
+
a
c
 a b + c d e + * *
Constructing Expression Tree from Postfix
Stack
b
+
a
c d
 a b + c d e + * *
Constructing Expression Tree from Postfix
Stack
b
+
a
c d e
 a b + c d e + * *
Constructing Expression Tree from Postfix
Stack
b
+
a
c
e
+
d
 a b + c d e + * *
Constructing Expression Tree from Postfix
Stack
b
+
a
*
c
e
+
d
 a b + c d e + * *
Constructing Expression Tree from Postfix
Stack
*
*
c
e
+
d
b
*
a
 a b + c d e + * *
Constructing Expression Tree from Postfix
Stack
*
*
c
e
+
d
b
*
a
root
(1+2) * ((3*(4+5))
Evaluation of a Binary Expression Tree
*
*
3
5
+
4
2
+
1
root
3
9
27
81
#include <iostream>
#include <string>
#include <math.h>
using namespace std;
struct Data{
char opr;
double num;
};
struct Tree_Node {
Tree_Node* left ;
Data data ;
Tree_Node* right ;
};
typedef Tree_Node* SType;
19
Implementation of Binary Expression Tree
struct Node{
SType info ;
Node *next ;
};
class Stack{
private :
Node* head;
public :
Stack( );
bool Is_Empty();
SType Top();
void Push ( SType Data );
SType Pop ( );
~Stack( ) ;
};
Stack::Stack( ){
head = NULL;
}
1 2
bool Stack::Is_Empty() {
return head == NULL;
}
SType Stack::Top() {
if ( !Is_Empty() )
return head->info;
return NULL;
}
void Stack :: Push ( SType Data ) {
Node *newNode ;
newNode = new Node ;
if ( newNode == NULL ){
cout << endl << "Stack is full" ;
return;
}
newNode -> info = Data ;
newNode -> next = head ; head = newNode;
}
20
Implementation of Binary Expression Tree
SType Stack :: Pop( ) {
if ( Is_Empty() ){
cout << "Stack is empty " ;
return NULL ;
}
Node *current ;
SType Data ;
current = head ;
Data = current -> info ;
head = head -> next ;
delete current ;
return Data ;
}
Stack :: ~Stack( ){
Node *current ;
while ( head != NULL ){
current = head ;
head = head -> next ; delete head ;
}
}
3 4
class Binary_Expression_Tree{
private:
Stack St;
Tree_Node* root;
Tree_Node* t,*t1,*t2;
void Pre_Order(Tree_Node* );
void In_Order(Tree_Node* );
void Post_Order(Tree_Node* );
bool Is_Operator(char c);
Tree_Node* New_Tree_Node(Data d);
double Evaluate (Tree_Node* node);
public:
Binary_Expression_Tree(){root = NULL;};
Binary_Expression_Tree(char Postfix[]);
double Evaluate( );
void Pre_Order ( );
void In_Order ( );
void Post_Order( );
};
21
Implementation of Binary Expression Tree
Tree_Node* Binary_Expression_Tree ::
New_Tree_Node(Data d){
Tree_Node* temp = new Tree_Node;
temp->left = NULL; temp->right = NULL;
temp->data = d;
return temp;
};
bool Binary_Expression_Tree ::
Is_Operator(char c){
switch(c){
case '+': return true;
case '-': return true;
case '*': return true;
case '/': return true;
case '^': return true;
default : return false;
}
return false;
}
5 6
Binary_Expression_Tree ::
Binary_Expression_Tree(char Postfix[]){
// Traverse through every character of
// input expression
for (int i=0; Postfix[i]; i++) {
// ignore space and tab
if( Postfix[i] == ' ' ||
Postfix[i] == 't')
continue;
// If operand, simply push into stack
if (!Is_Operator(Postfix[i])) {
Data d;
d.num = Postfix[i] - 0x30;
d.opr = 0;
t = New_Tree_Node(d);
St.Push(t);
}
22
Implementation of Binary Expression Tree
else { // operator
Data d;
d.num = 0;
d.opr = Postfix[i];
t = New_Tree_Node(d);
// Pop two top nodes
t1 = St.Pop(); // Remove top
t2 = St.Pop();
// make them children
t->right = t1;
t->left = t2;
// Add this subexpression to stack
St.Push(t);
}
}
// connect it with root pointer
root = St.Pop();
}
7 8
double Binary_Expression_Tree ::
Evaluate ( ) {
return Evaluate(root);
}
double Binary_Expression_Tree ::
Evaluate (Tree_Node* node) {
// empty tree
if (node == NULL)
return 0;
// leaf node i.e, an integer
if (node->left == NULL &&
node->right== NULL) {
return node->data.num;
}
23
Implementation of Binary Expression Tree
// Evaluate left subtree
double l_val = Evaluate(node->left);
// Evaluate right subtree
double r_val = Evaluate(node->right);
// Check which operator to apply
if (node->data.opr == '+')
return l_val + r_val;
if (node->data.opr == '-')
return l_val-r_val;
if (node->data.opr == '*')
return l_val*r_val;
if (node->data.opr == '/' )
return l_val/r_val;
if (node->data.opr == '^')
return pow(l_val,r_val);
return 0;
}
9 10
void Binary_Expression_Tree :: Pre_Order(){
Pre_Order(root);
}
void Binary_Expression_Tree ::
Pre_Order(Tree_Node *node){
if(node != NULL){
if (node->data.opr == 0)
cout << node->data.num << " ";
else
cout << node->data.opr << " ";
Pre_Order(node->left);
Pre_Order(node->right);
}
}
24
Implementation of Binary Expression Tree
void Binary_Expression_Tree :: In_Order ( ){
In_Order(root);
}
void Binary_Expression_Tree ::
In_Order(Tree_Node *node){
if(node != NULL){
In_Order(node->left);
if (node->data.opr == 0)
cout << node->data.num << " ";
else
cout << node->data.opr << " ";
In_Order(node->right);
}
}
11 12
void Binary_Expression_Tree :: Post_Order(){
Post_Order(root);
}
void Binary_Expression_Tree ::
Post_Order(Tree_Node *node){
if(node != NULL){
Post_Order(node->left);
Post_Order(node->right);
if (node->data.opr == 0)
cout << node->data.num << " ";
else
cout << node->data.opr << " ";
}
}
25
Implementation of Binary Expression Tree
int main(){
Binary_Expression_Tree
BET("1 2 + 3 4 5 + * *");
cout <<" -:Pre_Order Traversal:-n";
BET.Pre_Order();
cout <<"nn -:In_Order Traversal:-n";
BET.In_Order();
cout << endl;
cout <<"nn-:Post_Order Traversal:-n";
BET.Post_Order();
cout << endl;
cout << "Answer = "<< BET.Evaluate();
cout << endl;
system("PAUSE"); return 0;
}
13 14
Program Output

More Related Content

PDF
Write a program that accepts an arithmetic expression of unsigned in.pdf
PDF
Please read the comment ins codeExpressionTree.java-------------.pdf
PDF
Please write in C++ and should be able to compile and debug.Thank yo.pdf
PPTX
DS group binary tree all information M.pptx
PDF
Tree Traversals A tree traversal is the process of visiting.pdf
PDF
ANSimport java.util.Scanner; class Bina_node { Bina_node .pdf
PDF
MAINCPP include ltiostreamgt include ltstringgt u.pdf
PDF
Lab-2.4 101.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdf
Please read the comment ins codeExpressionTree.java-------------.pdf
Please write in C++ and should be able to compile and debug.Thank yo.pdf
DS group binary tree all information M.pptx
Tree Traversals A tree traversal is the process of visiting.pdf
ANSimport java.util.Scanner; class Bina_node { Bina_node .pdf
MAINCPP include ltiostreamgt include ltstringgt u.pdf
Lab-2.4 101.pdf

Similar to Data Structures and Agorithm: DS 14 Binary Expression Tree.pptx (20)

PPT
Unit8 C
DOCX
#include iostream using namespace std; const int nil = 0; cl.docx
PDF
(Parent reference for BST) Redefine TreeNode by adding a reference to.pdf
PDF
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
PDF
CS50 Lecture4
PDF
A)B) C++ program to create a Complete Binary tree from its Lin.pdf
DOCX
For this project, write a program that stores integers in a binary.docx
PDF
Given the following codepackage data1;import java.util.;p.pdf
PPT
Admissions in india 2015
PPT
DOCX
Binary Tree in C++ coding in the data structure
PDF
TutorialII_Updated____niceupdateprogram.pdf
DOCX
AvlTree.h#ifndef AVL_TREE_H#define AVL_TREE_H#include d.docx
DOCX
DS Code (CWH).docx
PDF
(1)Objective Binary Search Tree traversal (2 points)Use traversal.pdf
PPTX
Data Structures and Agorithm: DS 10 Binary Search Tree.pptx
PDF
Imugi: Compiler made with Python
PDF
Help to implement delete_node get_succ get_pred walk and.pdf
PPT
C++: Constructor, Copy Constructor and Assignment operator
PDF
I have C++ question that I do not know how to do, Can you teach me t.pdf
Unit8 C
#include iostream using namespace std; const int nil = 0; cl.docx
(Parent reference for BST) Redefine TreeNode by adding a reference to.pdf
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
CS50 Lecture4
A)B) C++ program to create a Complete Binary tree from its Lin.pdf
For this project, write a program that stores integers in a binary.docx
Given the following codepackage data1;import java.util.;p.pdf
Admissions in india 2015
Binary Tree in C++ coding in the data structure
TutorialII_Updated____niceupdateprogram.pdf
AvlTree.h#ifndef AVL_TREE_H#define AVL_TREE_H#include d.docx
DS Code (CWH).docx
(1)Objective Binary Search Tree traversal (2 points)Use traversal.pdf
Data Structures and Agorithm: DS 10 Binary Search Tree.pptx
Imugi: Compiler made with Python
Help to implement delete_node get_succ get_pred walk and.pdf
C++: Constructor, Copy Constructor and Assignment operator
I have C++ question that I do not know how to do, Can you teach me t.pdf
Ad

More from RashidFaridChishti (20)

PPTX
DBMS: Week 15 - Database Security and Access Control
PPTX
DBMS: Week 14 - Backup and Recovery in MySQL
PPTX
DBMS: Week 13 - Transactions and Concurrency Control
PPTX
DBMS: Week 12 - Triggers in MySQL Database Server
PPTX
DBMS: Week 11 - Stored Procedures and Functions
PPTX
DBMS: Week 10 - Database Design and Normalization
PPTX
DBMS: Week 09 - SQL Constraints and Indexing
PPTX
DBMS: Week 08 - Joins and Views in MySQL
PPTX
DBMS: Week 07 - Advanced SQL Queries in MySQL
PPTX
DBMS: Week 06 - SQL - Data Manipulation Language (DML)
PPTX
DBMS: Week 05 - Introduction to SQL Query
PPTX
DBMS: Week 04 - Relational Model in a Database
PPTX
DBMS: Week 03 - Data Models and ER Model
PPTX
DBMS: Week 02 - Database System Architecture
PPTX
DBMS: Week 01 - Introduction to Databases
DOCX
Lab Manual Arduino UNO Microcontrollar.docx
DOCX
Object Oriented Programming OOP Lab Manual.docx
DOCX
Lab Manual Data Structure and Algorithm.docx
PPTX
Data Structures and Agorithm: DS 24 Hash Tables.pptx
PPTX
Data Structures and Agorithm: DS 22 Analysis of Algorithm.pptx
DBMS: Week 15 - Database Security and Access Control
DBMS: Week 14 - Backup and Recovery in MySQL
DBMS: Week 13 - Transactions and Concurrency Control
DBMS: Week 12 - Triggers in MySQL Database Server
DBMS: Week 11 - Stored Procedures and Functions
DBMS: Week 10 - Database Design and Normalization
DBMS: Week 09 - SQL Constraints and Indexing
DBMS: Week 08 - Joins and Views in MySQL
DBMS: Week 07 - Advanced SQL Queries in MySQL
DBMS: Week 06 - SQL - Data Manipulation Language (DML)
DBMS: Week 05 - Introduction to SQL Query
DBMS: Week 04 - Relational Model in a Database
DBMS: Week 03 - Data Models and ER Model
DBMS: Week 02 - Database System Architecture
DBMS: Week 01 - Introduction to Databases
Lab Manual Arduino UNO Microcontrollar.docx
Object Oriented Programming OOP Lab Manual.docx
Lab Manual Data Structure and Algorithm.docx
Data Structures and Agorithm: DS 24 Hash Tables.pptx
Data Structures and Agorithm: DS 22 Analysis of Algorithm.pptx
Ad

Recently uploaded (20)

PPTX
"Array and Linked List in Data Structures with Types, Operations, Implementat...
PPTX
Fundamentals of safety and accident prevention -final (1).pptx
PDF
Soil Improvement Techniques Note - Rabbi
PPTX
Graph Data Structures with Types, Traversals, Connectivity, and Real-Life App...
PDF
Influence of Green Infrastructure on Residents’ Endorsement of the New Ecolog...
PDF
SMART SIGNAL TIMING FOR URBAN INTERSECTIONS USING REAL-TIME VEHICLE DETECTI...
PPTX
6ME3A-Unit-II-Sensors and Actuators_Handouts.pptx
PDF
UNIT no 1 INTRODUCTION TO DBMS NOTES.pdf
PDF
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
PPTX
ASME PCC-02 TRAINING -DESKTOP-NLE5HNP.pptx
PDF
Improvement effect of pyrolyzed agro-food biochar on the properties of.pdf
PPTX
CyberSecurity Mobile and Wireless Devices
PDF
Exploratory_Data_Analysis_Fundamentals.pdf
PPTX
Feature types and data preprocessing steps
PDF
Visual Aids for Exploratory Data Analysis.pdf
PDF
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
PPT
INTRODUCTION -Data Warehousing and Mining-M.Tech- VTU.ppt
PPTX
introduction to high performance computing
PPTX
Current and future trends in Computer Vision.pptx
PDF
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
"Array and Linked List in Data Structures with Types, Operations, Implementat...
Fundamentals of safety and accident prevention -final (1).pptx
Soil Improvement Techniques Note - Rabbi
Graph Data Structures with Types, Traversals, Connectivity, and Real-Life App...
Influence of Green Infrastructure on Residents’ Endorsement of the New Ecolog...
SMART SIGNAL TIMING FOR URBAN INTERSECTIONS USING REAL-TIME VEHICLE DETECTI...
6ME3A-Unit-II-Sensors and Actuators_Handouts.pptx
UNIT no 1 INTRODUCTION TO DBMS NOTES.pdf
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
ASME PCC-02 TRAINING -DESKTOP-NLE5HNP.pptx
Improvement effect of pyrolyzed agro-food biochar on the properties of.pdf
CyberSecurity Mobile and Wireless Devices
Exploratory_Data_Analysis_Fundamentals.pdf
Feature types and data preprocessing steps
Visual Aids for Exploratory Data Analysis.pdf
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
INTRODUCTION -Data Warehousing and Mining-M.Tech- VTU.ppt
introduction to high performance computing
Current and future trends in Computer Vision.pptx
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems

Data Structures and Agorithm: DS 14 Binary Expression Tree.pptx

  • 1. Data Structure Lecture No. 14 Binary Expression Tree Engr. Rashid Farid Chishti http://youtube.com/rfchishti http://sites.google.com/site/chishti International Islamic University H-10, Islamabad, Pakistan Video Lecture
  • 2.  Expression trees are binary trees for mathematical expression  Leaves are operands (a, b, c, …)  Other nodes are operators. (+, -, *, /)  This is Expression Tree for (a+b*c)+((d*e+f)*g) Binary Expression Tree + + * b a c * + g f * d e
  • 3.  Preorder traversal: (node, left, right) gives Prefix Expression. + + a * b c * + * d e f g Expression Tree Traversal + + * b a c * + g f * d e
  • 4.  Inorder traversal: (left, node, right) gives Infix Expression. a + b * c + d * e + f * g Expression Tree Traversal + + * b a c * + g f * d e
  • 5.  Postorder traversal: (left, right, node) gives Postfix Expression. a b c * + d e * f + g * + Expression Tree Traversal + + * b a c * + g f * d e
  • 6.  Read expression one symbol at a time  If the symbol is an operand  Create a one-node tree  Push its pointer to a stack  If the symbol is an operator  Pop two pointers  Form a new tree whose root is the operator  In the end, the only element of the stack will be the root of an expression tree. Constructing a Binary Expression Tree from Postfix
  • 7.  a b + c d e + * * Constructing Expression Tree from Postfix Stack
  • 8.  a b + c d e + * * Constructing Expression Tree from Postfix Stack a
  • 9.  a b + c d e + * * Constructing Expression Tree from Postfix Stack a b
  • 10.  a b + c d e + * * Constructing Expression Tree from Postfix Stack b + a
  • 11.  a b + c d e + * * Constructing Expression Tree from Postfix Stack b + a c
  • 12.  a b + c d e + * * Constructing Expression Tree from Postfix Stack b + a c d
  • 13.  a b + c d e + * * Constructing Expression Tree from Postfix Stack b + a c d e
  • 14.  a b + c d e + * * Constructing Expression Tree from Postfix Stack b + a c e + d
  • 15.  a b + c d e + * * Constructing Expression Tree from Postfix Stack b + a * c e + d
  • 16.  a b + c d e + * * Constructing Expression Tree from Postfix Stack * * c e + d b * a
  • 17.  a b + c d e + * * Constructing Expression Tree from Postfix Stack * * c e + d b * a root
  • 18. (1+2) * ((3*(4+5)) Evaluation of a Binary Expression Tree * * 3 5 + 4 2 + 1 root 3 9 27 81
  • 19. #include <iostream> #include <string> #include <math.h> using namespace std; struct Data{ char opr; double num; }; struct Tree_Node { Tree_Node* left ; Data data ; Tree_Node* right ; }; typedef Tree_Node* SType; 19 Implementation of Binary Expression Tree struct Node{ SType info ; Node *next ; }; class Stack{ private : Node* head; public : Stack( ); bool Is_Empty(); SType Top(); void Push ( SType Data ); SType Pop ( ); ~Stack( ) ; }; Stack::Stack( ){ head = NULL; } 1 2
  • 20. bool Stack::Is_Empty() { return head == NULL; } SType Stack::Top() { if ( !Is_Empty() ) return head->info; return NULL; } void Stack :: Push ( SType Data ) { Node *newNode ; newNode = new Node ; if ( newNode == NULL ){ cout << endl << "Stack is full" ; return; } newNode -> info = Data ; newNode -> next = head ; head = newNode; } 20 Implementation of Binary Expression Tree SType Stack :: Pop( ) { if ( Is_Empty() ){ cout << "Stack is empty " ; return NULL ; } Node *current ; SType Data ; current = head ; Data = current -> info ; head = head -> next ; delete current ; return Data ; } Stack :: ~Stack( ){ Node *current ; while ( head != NULL ){ current = head ; head = head -> next ; delete head ; } } 3 4
  • 21. class Binary_Expression_Tree{ private: Stack St; Tree_Node* root; Tree_Node* t,*t1,*t2; void Pre_Order(Tree_Node* ); void In_Order(Tree_Node* ); void Post_Order(Tree_Node* ); bool Is_Operator(char c); Tree_Node* New_Tree_Node(Data d); double Evaluate (Tree_Node* node); public: Binary_Expression_Tree(){root = NULL;}; Binary_Expression_Tree(char Postfix[]); double Evaluate( ); void Pre_Order ( ); void In_Order ( ); void Post_Order( ); }; 21 Implementation of Binary Expression Tree Tree_Node* Binary_Expression_Tree :: New_Tree_Node(Data d){ Tree_Node* temp = new Tree_Node; temp->left = NULL; temp->right = NULL; temp->data = d; return temp; }; bool Binary_Expression_Tree :: Is_Operator(char c){ switch(c){ case '+': return true; case '-': return true; case '*': return true; case '/': return true; case '^': return true; default : return false; } return false; } 5 6
  • 22. Binary_Expression_Tree :: Binary_Expression_Tree(char Postfix[]){ // Traverse through every character of // input expression for (int i=0; Postfix[i]; i++) { // ignore space and tab if( Postfix[i] == ' ' || Postfix[i] == 't') continue; // If operand, simply push into stack if (!Is_Operator(Postfix[i])) { Data d; d.num = Postfix[i] - 0x30; d.opr = 0; t = New_Tree_Node(d); St.Push(t); } 22 Implementation of Binary Expression Tree else { // operator Data d; d.num = 0; d.opr = Postfix[i]; t = New_Tree_Node(d); // Pop two top nodes t1 = St.Pop(); // Remove top t2 = St.Pop(); // make them children t->right = t1; t->left = t2; // Add this subexpression to stack St.Push(t); } } // connect it with root pointer root = St.Pop(); } 7 8
  • 23. double Binary_Expression_Tree :: Evaluate ( ) { return Evaluate(root); } double Binary_Expression_Tree :: Evaluate (Tree_Node* node) { // empty tree if (node == NULL) return 0; // leaf node i.e, an integer if (node->left == NULL && node->right== NULL) { return node->data.num; } 23 Implementation of Binary Expression Tree // Evaluate left subtree double l_val = Evaluate(node->left); // Evaluate right subtree double r_val = Evaluate(node->right); // Check which operator to apply if (node->data.opr == '+') return l_val + r_val; if (node->data.opr == '-') return l_val-r_val; if (node->data.opr == '*') return l_val*r_val; if (node->data.opr == '/' ) return l_val/r_val; if (node->data.opr == '^') return pow(l_val,r_val); return 0; } 9 10
  • 24. void Binary_Expression_Tree :: Pre_Order(){ Pre_Order(root); } void Binary_Expression_Tree :: Pre_Order(Tree_Node *node){ if(node != NULL){ if (node->data.opr == 0) cout << node->data.num << " "; else cout << node->data.opr << " "; Pre_Order(node->left); Pre_Order(node->right); } } 24 Implementation of Binary Expression Tree void Binary_Expression_Tree :: In_Order ( ){ In_Order(root); } void Binary_Expression_Tree :: In_Order(Tree_Node *node){ if(node != NULL){ In_Order(node->left); if (node->data.opr == 0) cout << node->data.num << " "; else cout << node->data.opr << " "; In_Order(node->right); } } 11 12
  • 25. void Binary_Expression_Tree :: Post_Order(){ Post_Order(root); } void Binary_Expression_Tree :: Post_Order(Tree_Node *node){ if(node != NULL){ Post_Order(node->left); Post_Order(node->right); if (node->data.opr == 0) cout << node->data.num << " "; else cout << node->data.opr << " "; } } 25 Implementation of Binary Expression Tree int main(){ Binary_Expression_Tree BET("1 2 + 3 4 5 + * *"); cout <<" -:Pre_Order Traversal:-n"; BET.Pre_Order(); cout <<"nn -:In_Order Traversal:-n"; BET.In_Order(); cout << endl; cout <<"nn-:Post_Order Traversal:-n"; BET.Post_Order(); cout << endl; cout << "Answer = "<< BET.Evaluate(); cout << endl; system("PAUSE"); return 0; } 13 14