|
General Details
|
|
Scheme
|
|
Posted 94 Days Ago
|
|
214 Views
|
|
Received 0 Ratings
|
|
Pre, in, post order traversal of a binary tree.
Description
Here's an example of traversing a binary tree in three different ways, pre-order, in-order, and post-order. I made the functions bracket the expressions so that they are easier to read. For instance, 2 * 4 + 5 * 6 is actually printed as ( (2 * 4) + (5 * 6) ).
This program is the first step in a little app I want to make that can convert infix notation (like 2 + (4 / (3+5)) - (4 + 4) ) into Scheme's pre-fix notation. (like: (- (+ 2 (/ 4 (+ 3 5))) (+ 4 4)) )
This program could then be used to help beginner Scheme programmers understand complicated arithmetic operations in pre-fix notation. The only thing I need to figure out is how Scheme handles string processing. If someone knows how to do this, could they point me in the right direction? I might just make a C++ front-end that accesses this code, which I also have to explore.
Please let me know if there are any ways that I can improve this code. Thanks.
Technical
Output:
(+ (* 2 3 )(* 4 5 ))
((2 * 3 )+ (4 * 5 ))
((2 3 * )(4 5 * )+ )
Source Code
Comments
| Please login to post comments. |
|
|
Hi,
you might want to look at srfi-13 for string procedures. But why bother strings, when you can work on lists? :)
|
More "Scheme" Source Codes By This Author
Recently Posted "Scheme" Source Codes
Recently Rated "Scheme" Source Codes
|