Question
Please answer this question in racket language. The template is given below Template #lang racket ;; Please, do not remove this line and do not
Please answer this question in racket language. The template is given below Template
#lang racket ;; Please, do not remove this line and do not change the function names, (provide (all-defined-out))
(define ex1 'todo) (define ex2 'todo) (define ex3 'todo)
;; 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)
3. (7 points) Your goal is to implement a Binary Search Tree (BST) in Racket, as we learned in Lecture 3 user data-structures) To this end, you will need to implement the constructor and selectors of each field, as well as the operation to insert a node in the BST. Please use the function names declared in the homework assignment template, as otherwise you will get 0 points in this assignment. The following code is a Java implementation of binary tree taken from the Wikipedia page on BST class Tree Tree left, right; float value; Tree(Tree left, float value, Tree right) f this.left-left; this.value-value; this.right - right; Tree setLeft (Tree left) return new Tree(left, this.value, this.right); h Tree setValue(float value) return new Tree(this.left, value, this.right); ) Tree setRight(Tree right) return new Tree(this.left, this.value, right); ) static Tree insert (Tree node, float value) if (node -nul1) return new Tree(null, value, null); if (value node.value) return node.setValue(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