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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started