Question
Problem(Python/Racket). There is some code for creating a Binary Search Tree by Python: Please translate the algorithm( not to rethink the algorithm) to
Problem(Python/Racket). There is some code for creating a Binary Search Tree by Python:
Please "translate" the algorithm(not to rethink the algorithm) to Racket, creating BST in Racket.
Attention:
The equivalent of None in Racket is null. The equivalent of testing if a value is None in Racket is to call function null?.
Simply, please complete these functions by edit the "'todo" to full their content.
BST.rkt
#lang racket
;; Constructs a tree from two trees and a value (define (tree left value right) 'todo)
;; Constructs a tree with a single node (define (tree-leaf value) 'todo)
;; Accessors (define (tree-left self) 'todo) (define (tree-value self) 'todo) (define (tree-right self) 'todo)
;; Copies the source and updates one of the fields (define (tree-set-value self value) 'todo) (define (tree-set-left self left) 'todo) (define (tree-set-right self right) 'todo)
;; Function that inserts a value in a BST (define (bst-insert self value) 'todo)
class Tree: def _init_(self, left, value, right): self.left = left; self.value = value; self.right = right; def set_left(self, left): return Tree(left, self.value, self.right) def set_value(self, value): return Tree(self.left, value, self.right) def set_right(self, right): return Tree(self.left, self.value, right) def insert(node, value): if node is None: return Tree(None, value, None) if value = node.value: return node.set_value(value) if valueStep 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