This week, we had our 2nd midterm test. It was actually not difficult, but I struggled with it as it required applying my knowledge of code for recursion. I don't think I did well in the test as I know that I didn't know how to implement the body of the classes given. This is because I found it difficult to apply my knowledge from lecture. It is easy to read code and a little tough to understand it, but it is a lot tougher to apply the knowledge.
After, the professor covered linked lists even further and showed us some code on how to "walk through" the linked list. I learnt two ways of thinking of linked list structures: as lists made up of an item (value) and a sub-list (rest), and as objects (nodes) with a value and a reference to other similar objects.
To make a reference to other objects, the professor showed us two initialized variable in class LLNode, value and nxt. We were also shown how a wrapper class for a list is made, by initializing variables front, back and size.
To walk through a list, we were shown that we had make a reference to at least one node, and move it along the way. I found the code relatively simple to understand, as it just involved initializing the variable as the front of the list, and while there were elements behind, the variable kept referring to the element behind the current one. The general outline of the code for this is as follows:
cur_node = self.front
while <some condition here...>:
# do something here...
cur_node = cur_node.nxt
We were also taught a few more methods associated with linked lists, such as implementing __contains__, __getitem__, and delete_back briefly. Overall, this was a relatively easy lecture to understand, but this is just the theory. The practical applications is where I will really need to apply and hone my knowledge in.
After, the professor covered linked lists even further and showed us some code on how to "walk through" the linked list. I learnt two ways of thinking of linked list structures: as lists made up of an item (value) and a sub-list (rest), and as objects (nodes) with a value and a reference to other similar objects.
To make a reference to other objects, the professor showed us two initialized variable in class LLNode, value and nxt. We were also shown how a wrapper class for a list is made, by initializing variables front, back and size.
To walk through a list, we were shown that we had make a reference to at least one node, and move it along the way. I found the code relatively simple to understand, as it just involved initializing the variable as the front of the list, and while there were elements behind, the variable kept referring to the element behind the current one. The general outline of the code for this is as follows:
cur_node = self.front
while <some condition here...>:
# do something here...
cur_node = cur_node.nxt
We were also taught a few more methods associated with linked lists, such as implementing __contains__, __getitem__, and delete_back briefly. Overall, this was a relatively easy lecture to understand, but this is just the theory. The practical applications is where I will really need to apply and hone my knowledge in.
No comments:
Post a Comment