COMP 202: Principles of Object-Oriented Programming II← Exam1 Review Lab → |
Home — Fall 2008 | | | Information | | | Resources | | | Exam Resources | | | OwlSpace | | | COMP 201 |
Here are some practice exercises to help you prepare for Exam 1:
The result of running the InOrder1 visitor with your lambda on the above BiTree should be a single string with the familiar algebraic notation:f1 |_ a | |_[] | |_[] |_f2 | |_f3 | |_b | | |_[] | | |_[] | |_c | |_[] | |_[] |_f4 |_[] |_d |_[] |_[]f1(a, f2(f3(b, c), f4(d)))
An empty tree would return an empty string and a single element tree would return a string with just that element in it.
Do not assume that the tree holds Strings. Use the data's toString() method to get a string representation of that data.
Is this actually an in-order tree traversal?
Here is a zip file with a pre-built project including test cases where the body of AlgebraicRep has been deleted for your convenience: biTreeCode.zip :-) (also contains code for Prob. 6)
Map(f, inp, {x1, x2, x3, ....}) = {f(x1, inp), f(x2, inp), f(x3, inp), ...}
MapLRS mutates the host LRStruct. The constructor of MapLRS should take the ILambda that it is going to use. The input parameter(s) to the lambda are the input parameters to the Map visitor.
The return value of the ILambda can be used to control the mapping process. Let the ILambda be defined as returning a Boolean object. If the return value is Boolean.TRUE, continue mapping. Otherwise stop mapping.
MapLRS should return a reference to the host LRStruct.
Write some test lambdas to check if you mapping is working properly:
- Square every integer in a list of integers (Square).
- Append a string onto every string in a list of strings (AppendStr)
- Replace every negative value in a list of integers with its positive counterpart (AbsVal)
- Replace every string in a list of strings with another string unless a particular stop string is encountered, at which point, stop mapping. The element containing the stop string is not replaced. The stop string is given to the constructor of the lambda. (ReplaceStr)
Here is a zip file with all the necessary classes with a pre-built project with test code and all student code graciously stubbed out: mapFoldCode.zip (contains code for Probs. 4 & 5 too).
{} ==> {0}
{a, b, c, d, ...}
==> {..., a+b+c+d, a+b, a, 0}
NOTE: The definitions of FoldlLRS
and FoldrLRS used here are slightly
different than that used in class: Foldl/r passes
host not
host.getFirst() to the lambda.
What do you expect to happen if you run this lambda using
FoldrLRS?
The download for Prob. 3 contains the test code and stubs for this problem.
The download for Prob. 3 contains the test code and stubs for this problem.
The download for Prob. 2 contains the test code and
stubs for this problem.
Solutions for the above problems -- no peeking!!
URL: http://www.cs.rice.edu/teaching/202/08-fall/labs/review1/index.shtml
Copyright © 2008-2010 Mathias Ricken and Stephen Wong