Question: Write a recursive procedure called reverse that takes a binary tree BinTree as input and returns its reverse as the output. A binary tree is
Write a recursive procedure called reverse that takes a binary tree BinTree as input and returns its reverse as the output.
A binary tree is reversed if its left subtree is replaced with its right subtree and vice versa.
Below are a few examples of inputs/outputs of the reverse procedure.
> (reverse 7)
7
> (reverse '(+ 7 8))
'(+ 8 7)
> (reverse '(* (+ 7 8) (- 10 11) ) )
'(* (- 11 10) (+ 8 7) )
BinTree is defined by the following grammar. In this grammar, Int denotes an integer number and Symbol denotes +,-,/ and *.
Bintree ::= Int | (Symbol Bintree Bintree)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
