Den man. 27. apr. 2020 kl. 04.36 skrev Kristina Marie <[email protected]
>:

> 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))
>
...

> ; 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))))
>            ]
>        )
>      )
>
>
This expression
     (bst-sort (node-left nod) (list (node-value nod)) (bst-sort
(node-right nod))))
is the problem. It can be reformatted to make it clearer:

     (bst-sort (node-left nod)
                   (list (node-value nod))
                    (bst-sort (node-right nod))))

You are providing 3 arguments to bst-sort, but according to your signature:
    ; Signature: node -> list
it only takes one input.

Furthermore the `string-append` needs to be removed, since bst-sort returns
a list, not a string.

/Jens Axel



> 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
> <https://groups.google.com/d/msgid/racket-users/e5e05ebe-87ed-4d49-8a18-d3b58bae4e38%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>


-- 
-- 
Jens Axel Søgaard

-- 
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/CABefVgyyOCTLVomOhEWtOT%3DOOOdyNM%2BxcSEee4kdDctbspBDOg%40mail.gmail.com.

Reply via email to