Before I begin
to talk about my last impression about the Slog, I promised you guys with the
answers to the functions. (Hope someone
actually tried and has been looking for the answer!)
def __contains__(self, value):
''' (LinkedList, object)
-> bool
Return whether LinkedList contains the value.
>>> lnk =
LinkedList()
>>> lnk.prepend(0)
>>> lnk.prepend(1)
>>> lnk.prepend(2)
>>>
lnk.__contains__(1)
True
>>>
lnk.__contains__(3)
False
'''
current_node = self.front
while current_node:
if value ==
current_node.value:
return True
current_node =
current_node.nxt
return False
def delete_back(lnk):
''' (LinkedList) ->
NoneType
Delete back node of lnk, if
it exists, otherwise do not change anything .
>>> lnk =
LinkedList()
>>> lnk.prepend(5)
>>> lnk.prepend(7)
>>>
print(lnk.front)
7 -> 5 ->|
>>>
delete_back(lnk)
>>> lnk.size
1
>>>
print(lnk.front)
7 ->|
>>>
delete_back(lnk)
>>> lnk.size
0
>>>
print(lnk.front)
None
'''
if lnk.size > 0:
prev_node, cur_node =
None, lnk.front
while cur_node.nxt:
prev_node = cur_node
cur_node =
cur_node.nxt
lnk.back = prev_node
if lnk.back is None:
lnk.front = None
else:
lnk.back.nxt = None
lnk.size -= 1
def append(lnk, value):
''' (LinkedList, object) -> NoneType
Insert a new node with value at back of lnk.
>>> lnk = LinkedList()
>>> lnk.append(5)
>>> lnk.size
1
>>> print(lnk.front)
5 ->|
>>> lnk.append(6)
>>> lnk.size
2
>>> print(lnk.front)
5 -> 6 ->|
'''
new_node = LLNode(value)
if lnk.back:
lnk.back.nxt = new_node
lnk.back = new_node
else:
lnk.back = lnk.front = new_node
def prepend(self, value):
''' (LinkedList, object)
-> Nonetype
Insert value at front of
LLNode.
>>> lnk =
LinkedList()
>>> lnk.prepend(0)
>>> lnk.prepend(1)
>>> lnk.prepend(2)
>>> str(lnk.front)
'2 -> 1 -> 0 ->|'
>>> lnk.size
3
'''
self.front = LLNode(value,
self.front)
if self.back is None:
self.back = self.front
self.size += 1
def
print_backward(lnk):
'''(LinkedList) -> str
Print the Nodes in the LinkedList backwards.
>>> lnk = LinkedList()
>>> lnk.prepend(0)
>>> lnk.prepend(1)
>>> lnk.prepend(2)
>>> print_backward(lnk)
'0 -> 1 -> 2 ->|'
'''
if lnk == None :
return print_backward(lnk.next)
print(lnk)
----------------------------------------------------------------------------------------------------------------------------------
I can’t believe
that this is the last post of the CSC148 Slog.
There were many
events happened throughout the entire year, good and bad.
I cannot forget
the moment my colleagues and I got 95% on first assignment, and the time when I
received 88% on my first test.
I also cannot
forget how badly we did on the second assignment because we underestimated how
time consuming A2 was.
However, from
the mistakes, I focused on writing slogs in more detail and willing to seek for
help in Piazza & TA.
Then, I received
100%, my first 100% in university career, and I cannot explain how rewarding it
felt like.
After that my
colleagues (Amir and Matt) worked hard with me to ace the third and last
assignment and I believe we did a great job on it.
CSC148 was an
introduction class but some parts were still challenging. I must say that keeping up with posts is
not the easiest thing to do, but if you manage to do so, I guarantee that you will
achieve fairly good marks in the course. It
does not have to be computer science course; it can be any courses like math or
statistics, anything.
Comparing
myself from last semester when I disliked the concepts of Slogs, my views on
Slogs are 180 degree different. I am planning
on sharing my knowledge I consume in class by posting it online and I truly believe
that it will improve my understanding in courses in the future.
It was a great
journey with myself, Professor Horton, Professor Heap, my colleagues, and the
readers, but I believe it is a time to put an end in CSC148 blog.
It has been a
great semester with you all and I wish you the best in whatever you do in the
future for those who read this.
Cheers,
SeungHyun
(Sonny) Kim
P.S Don’t
forget to check out these blogs as well, they are very interesting.
http://mattfcheung148.blogspot.ca (my colleague)
http://bloggermcbloggerman.blogspot.ca -> has a very cool design
https://uberweirdesuu.wordpress.com -> very personal, check it out if you want to see personal style of posts!