EXPRESSION TREE
Aim:
To
write a C program to demonstrate an expression tree.
Algorithm for Main ()
Step 1: [ INCLUDE NECESSARY HEADER FILES]
Step 2: [READ X]
Step 3:[ CALL EXPTREE(),CALL
DISPLAY(), CALL INORDER(),CALL
PREORDER(),CALL EVALUATE ()]
Algorithm for
EXPTREE()
Step
1: Read Character
Step
2: IF Character operator then
CALL
PUSH_OP()
Step
3: [IF Character has only numbers]
IF
[ is ALnum( str[i] 1 )] THEN
CREATE
Newnode
Step
4: Check for ‘ NULL ‘ condition
Step
5: ASSIGN priority
Step
6: IF ( Priority !=0) THEN CALL POP_OP()
Step
7: IF Character = ‘)’ THEN CALL PUSH_OP()
Algorithm for INORDER
(tree t)
Step
1: IF (t!=NULL) THEN
CALL
INORDER(t left)
Step
2: PRINT t element
Step
3: CALL INORDER(t right)
Algorithm for PREORDER
(tree t)
Step
1: IF (t!=NULL) THEN
PRINT
t element
Step
2: CALL PREORDER(t left)
Step 3: CALL
INORDER(t right)
Algorithm for
POSTORDER(tree t)
Step
1: IF (t!=NULL) THEN
CALL
POSTORDER(t left)
CALL POSTORDER(t right)
Step 2: PRINT t element
No comments:
Post a Comment