EECS 12 Summer 2006 Homework 5

General Instructions

Please place your programs in seperate files named as described in the problem. Improperly named programs will not count. Turn in your files by placing them in the dropbox. Please be mindful of the late policy.

Grading

Correct80%
Commented10%
Attempted10%

Problems

Problem 0: 50 points

Create a program that turns nested lists into tree objects and vice-versa.

Hint: You can multiply a string by an integer to get multiple copies of a string. '*'*5 is the same as '*****'

You should be able to create a list in the specified format, convert it into a tree, convert that tree into a list, and then convert the list into a tree again. When printed, the trees should look the same.

Include the following test code in your file:

root = MakeTree([1,[[2,[[3,[]],[4,[]]]],[5,[[6,[]],[7,[]]]]]])
asList = DumpToList(root)
PrintTree(root,0)
PrintTree(MakeTree(asList),0)

It should print out the following:

 1
* 2
** 3
** 4
* 5
** 6
** 7
 1
* 2
** 3
** 4
* 5
** 6
** 7

Problem 1: 50 points

Modify your program from 4.1:

? range 1-
Bad value
? range 10 11
Wrong number of arguments
? range 10
Result: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
? savedisk ten
Result: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
? quit
Goodbye!
######### NEW RUN OF PROGRAM ########
? loaddisk cow
No such file: cow
Result: []
? loaddisk ten
Result: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]