I
think this lab was the first that I found quite difficult, aside from
maybe the second one. I thought I'd understood the linked list
structure, but when doing this lab, I had a lot of trouble coming up
with the solutions. For instance, for the __setitem__, __delitem__,
and insert methods, I didn't know how to find the position and modify
the item at that position. I kept thinking of using the __getitem__
method to find the item at the given index, but then realized that I
couldn't do anything with the returned value because it was just a
value, not an attribute that I could set to modify the list.
def
__setitem__(self, ind, val):
if self.empty or ind < 0:
if self.empty or ind < 0:
raise
IndexError
else:
self.__getitem__(ind)
= val
But
I did realize that this would not work, and I knew I should've been
using recursion, but...I couldn't think of a way to do it. After some
help from the T.A. I mostly got that we could keep checking a smaller
and smaller portion of the list and somehow, at the end, when the
index in question is the beginning of the list, it would be the item
attribute of the LinkedList and we can set it as so. I'm currently
still trying to understand this better.
As
for Assignment 2, well, this was quite a confusing concept. It took
me a long time to understand what we were “designing”, and then
what we had to write and did not have to write for this section.
After figuring out that we just had to create classes for the
different types of RegexTrees and implement their attributes, it was
easier to get started. However, I wasn't so sure about the
inheritance choices that I made, because I think I still had some
repeated code. I also used BarTree's __init__method in my DotTree
class, which probably wasn't the best idea now that I think about it,
but I didn't know how to get rid of that bit of duplicate code. All
in all, I didn't find it too difficult to write but I was quite
unsure of the design choices that I made.
No comments:
Post a Comment