Hello,
I am trying to use HtDF to create a function to sort a Binary Search Tree.
I am in an intro class so this may be a simple question. I did the
following:
;define-struct a node
(define-struct node (left value right))
;BTS leafs
(define a-node(make-node null "A" null))
(define b-node (make-node null "B" null))
(define e-node (make-node null "E" null))
(define h-node (make-node null "H" null))
(define i-node (make-node null "I" null))
;BTS internal
(define c-node (make-node a-node "C" b-node))
(define j-node (make-node h-node "J" i-node))
(define k-node (make-node j-node "K" null))
(define f-node (make-node e-node "F" null))
(define g-node (make-node f-node "G" k-node))
;Root
(define root (make-node c-node "D" g-node))
; Purpose: sort a binary tree
; Signature: node -> list
; Examples:
(check-expect (bst-sort null)(list))
(check-expect (bst-sort a-node)(list "A"))
(check-expect (bst-sort j-node)(list "H" "I" "J"))
(check-expect (bst-sort root)(list "A" "B" "C" "D" "E" "F" "G" "H" "I" "J"
"K"))
;Code
(define (bst-sort nod)
(cond
[(null? nod)(list)]
[(and (null? (node-left nod)) (null?(node-right nod))) (list(node-value
nod))]
[else
(string-append (bst-sort (node-left nod) (list (node-value nod))
(bst-sort (node-right nod))))
]
)
)
I keep getting this test failure:
bst-sort: expects only 1 argument, but found 3
It has to due with the two last check-expects failing because of the
highlighted line.
I ran this same code with integers and removed the string from append and
it passed. Any advice?
--
You received this message because you are subscribed to the Google Groups
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/racket-users/e5e05ebe-87ed-4d49-8a18-d3b58bae4e38%40googlegroups.com.