troubleshooting Question

Binary trees in Scheme

Avatar of speedingcars2012
speedingcars2012 asked on
Programming Languages-OtherPuzzles / RiddlesEncryption
3 Comments1 Solution3051 ViewsLast Modified:
I'm taking a computer class that uses Scheme and I'm having tons of trouble with the language. I've programmed with C++ and visual basic before so I understand the general idea of programming but I can never get the Scheme syntax right and a lot of the language is downright clunky. These are a few of the problems:

function 1
Develop the function inorder. It consumes a binary tree and produces a list of all the ssn numbers in the tree. The list contains the numbers in the left-to-right order

I don't know where to start with this one. I understand the physical aspect of the binary tree but not how to make one, much less put one in order.

I realize scheme is a icky old language, so if you need a point of reference, we're using an online book at
and I'm using the compiler Dr. scheme with the language beginning student with list abbreviations, if that's relevant at all. it's available at
;;class notes from for a binary tree. this is just an example of a binary tree, but I don't think it's applicable for this question. the example sort've helped me so I thought I'd post it
(define-struct bst (ssn left right))
(make-ssn 312045678)
(make-ssn 312012793)
(make-ssn 312459012)
(make-ssn 342147890)
(define (merge alon1 alon2)
    [(empty? alon1) alon2]
    [(empty? alon2) alon1]
    [(< (first alon1) (first alon2))
     (cons (first alon1) (merge (rest alon1) alon2))]
     (cons (first alon2) (merge alon1 (rest alon2)))]))
(define (make-singles l)
    [(empty? l) '()]
    [else (cons (list (first l)) (make-singles (rest l)))]))
(define (merge-neighbors alol)
    [(empty? alol) '()]
    [(empty? (rest alol)) alol]
    [else (cons
           (merge (first alol) (second alol))
                  (merge-neighbors (cddr alol)))]))
(define (merge-sort l)
    [(empty? l) '()]
    [else (repeat-merge (make-singles l))]))
(define (repeat-merge l)
  (cond [(empty? (rest l)) (first l)]
        [else (repeat-merge (merge-neighbors l))]))
(check-expect (merge-sort
               '(5 3 4 9 2)) '(2 3 4 5 9))

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros