Author | Message |
---|---|
msargent
Posts: 519
|
Posted 09:00 Oct 09, 2012 |
Sorry for the lateness of the post, but I'm having trouble figuring out how to filter0. I figure what we're supposed to do is traverse the original tree recursively while including the element of the member visted in another tree that gets passed as an accumulator into each call to filter0. I also figure it involves the left and right tails, but I don't know how to include both. Here's what I have for filter0 for NonEmpty
def filter0(p: Tweet => Boolean, accu: TweetSet): TweetSet =
if (!p(elem)) accu
else if (!left.isEmpty)left.filter0(p, incl(elem))
else right.filter0(p, incl(elem))
for Empty
def filter0(p: Tweet => Boolean, accu: TweetSet): TweetSet = accu
Last edited by msargent at
09:12 Oct 09, 2012.
|
rabbott
Posts: 1649
|
Posted 14:01 Oct 09, 2012 |
Your statement of the general problem is right. You don't have to use the tree structure, though. You can use head and tail. Your code for Empty is right. For NonEmpty you are not calling filter0 recursively if !p(elem) Also, as I said, you can use head and tail instead of elem, left, and right. Last edited by rabbott at
14:02 Oct 09, 2012.
|