我正在嘗試從字符串輸入中構造計劃語言的樹。以下是我已經嘗試 -從符號輸入構造樹
(define travsal (lambda (tree)
(cond
((null? tree) '())
(#t (append (travsal (car tree)) (cons (cadr tree)
(travsal (caddr tree))))))))
(define tree1 '(((() 4()) 2 (() 5())) 1 ((() 6()) 3 (() 7()))))
(display tree1)
(newline)
(travsal tree1)
正如你可以看到它只是迭代所提供的輸入,而不是做什麼實際的二叉樹應該做的。 對於如何使用節點和孩子從符號輸入保存樹來說,我感到非常震驚,例如 - (((()4())2(()5()))1((()6() )3(()7()))))「然後打印出來就像上面的功能正在打印。
請幫忙,我在接受採訪時被問到這個問題,仍然無法解決它。
現在他們在面試中提出了計劃問題?太棒了!這份工作在哪裏,我可以申請嗎? :P – 2014-08-28 23:30:29