During week 8, we learnt about linked list and LLNode. Learning linked list was difficult compared to other aspects of computer science. What professor Danny emphasized on was to draw pictures for linked lists. At first, I was not used to drawing diagrams to represent linked lists. However, I practiced drawing diagrams to understand linked lists. Interestingly, the last question of the test actually asked for a diagram for linked lists.
LLNode was very easy to understand as it is a node for linked list. I would like to demonstrate implementations to initialize LLNode and LinkedList based on Danny's lectures. (Source: http://www.cdf.utoronto.ca/~csc148h/winter/Lectures/Danny/W8/node.py)
class LLNode:
def __init__(self, value, nxt=None):
""" (LLNode, object, LLNode) -> NoneType
Initialize LLNode with value and nxt
"""
self.value, self.nxt = value, nxt
class LinkedList:
def __init__(self):
""" (LinkedList) -> NoneType
Initialize LinkedList self by making an empty linked list.
"""
self.front, self.back = None, None
self.size = 0
(Source: http://www.cdf.utoronto.ca/~csc148h/winter/Lectures/Danny/W8/node.py)
The most difficult part was to implement methods like __contains__ in order to find whether it contains a certain number or word. So I would like to go over __contains__ method on this post. The following implementation for __contains__ is from Danny's slides. I added comments to go over the implementation step by step. (Source: http://www.cdf.utoronto.ca/~csc148h/winter/Lectures/Danny/W8/node.py)
def __contains__(self, value):
""" (LinkedList, object) -> bool
Return True iff LinkedList self contains value.
"""
cur_node = self.front #Here we set a new variable called cur_node
while cur_node: #check whether cur_node exists
if cur_node.value == value: # if the first element of LinkedList contains value
return True # return True
cur_node = cur_node.nxt # if not, we move onto the next element of LinkedList
return False # there is no cur_node as it reached the end of LinkedList
(Source: http://www.cdf.utoronto.ca/~csc148h/winter/Lectures/Danny/W8/node.py)
Learning about LinkedList enabled me to understand computer science in depth. Although it's just a basic material for typical computer scientists, it is a huge achievement for a newcomer like me to learn and understand LinkedList concepts.
During this week, I spent three days studying for CSC 148 term 2 test. I first reviewed Danny and Diane's lecture slides and lab materials. Then, I tried solving five past exams. What I always had the challenge the most was LinkedList part. In order to overcome this challenge, I tried implementing new methods for class LinkedList. Not only that, I always tried to solve the past exam within 50 minutes. The term test was not that hard, but the last question was quite confusing to me. Sadly, the last question was about LinkedList. Although I am not 100% sure about my answer for the last question, I tried my best, so I have no regret. I hope to achieve A on this term test.
I also visited other students' SLOGs in order to learn how other students approach CSC148 and its course materials. Unfortunately, some of the SLOGs were inactive. The following links are the SLOG posts which I found interesting and left some comments.
http://148wuboyangw3.blogspot.ca/
http://computersciencemaggie.blogspot.ca/2015/03/summary-of-object-oriented-programming.html?showComment=1426384453547
http://csc148slog1001429162.blogspot.ca/2015/03/linked-lists.html#comment-form
No comments:
Post a Comment