Take the tour ×  I am trying to implement a breadth first
(level) tree traversal. I'm very close, but I can't figure out
how I'm getting duplicates. Any help is much appreciated. Thanks
in advance. JR  (define (atom? x)   (not (pair? x)))
;;Functions to manipulate a binary tree (define (leaf? node)
(atom? node)) (define (left node) (cadr node)) (define (right
node) (caddr node)) (define (label node) (if (leaf? node) node
(car node)))  ;; Breadth First using queue (define (breadth
node)   (q 'enqueue! node)              ;; Enqueue tree
(output 'enqueue! (label node)) ;; Output root   (helper node)
(output 'queue->list)           ;; Output elements in queue
(define (helper node)     (if (not(q 'empty?))          ;; If
queue is not empty        (if(not(leaf? node))           (q
'enqueue! (left node))          ;;  left tree to q
(output 'enqueue! (label(left node)))   ;; Output root of left
tree           (q 'enqueue! (right node))         ;; Enqueue
right tree to q           (output 'enqueue! (lab