我是Racket的初学者,最近我在球拍树上工作,我不知道如何平衡BST ,,,我写了一个代码来插入和建立一个BST但是可以'平衡BST(我的代码插入并构建BST)
(define (insert element tree)
(cond ((null? tree)(list element '() '()))
((= element (car tree)) tre)
((< element (car tree))(list (car tree) (insert element (cadr tree)) (caddr tree)))
(else (list (car tree) (cadr tree) (insert element (caddr tree))))))
(define (build-BST L)
(build-BST-helper L '()))
(define (build-BST-helper L tree)
(cond ((null? L) tree)
(else (build-BST-helper (cdr L) (insert (car L) tree)))))
提前thx :) ,,,对不起我的英文