Saturday, 7 March 2015

SLOG #6 ALL ABOUT LINKED LISTS

It seems the second midterm is coming up next week. Since the first midterm, we have learnt recursion, and abstract data types(stacks, queues, trees, and linked lists).  I think the second midterm will consist of questions mostly from these topics. Luckily, I have grasped the notions and implementations of recursion and most of the abstract data types quite well from the labs. However, I find linked lists, what we are learning this week, quite tricky.

Diane introduces two classes to represent linked lists: LLNode, and LinkedList. LLNode is a node of a linked list. It has instance variables: value and nxt: value is the object stored in the current linked list node, and nxt points to the next node. While LLNode represents only one node of the whole linked list, the class LinkedList gives us a more comprehensive view of a linked list. An LinkedList object has three attributes: front is the first node in the linked list, back is the last node in the linked list, and size is the number of nodes in the linked list.  Graphically, a linked list looks like this:
Although a linked list seems to be much simpler than a tree. But it turns out that for me, implementing functions and methods of linked list is difficult; it just doesn't work as I expected. I noticed this when I was trying to solve the lab of this week. I thought there would be a tutorial this week so I went to cdf lab on Thursday at 9 am. I only saw other two csc148 fellows in the lab so I knew the tutorial was cancelled. But I did not leave. Instead I tried to solve the questions in the lab handout as usual, thinking it won't take long before I finish implementing all the functions and methods. But after I spent more than 40 minutes trying to make the special method __add__ work, I got paranoid because the algorithms I had in my mind does not work when I typed them in code, and I could not figured out what was wrong. I didn't have time to finish all the functions on that day, possibly because I didn't actually follow the instruction to draw the graphs as required in the lab handout but rather picture linked lists in my mind. I'm going to try again after I finish this slog, and I will draw pictures to help my thinking. Hopefully this will work out. 

No comments:

Post a Comment