This week, we learned about linked lists. This was a little hard for me to grasp. After class, I had to review it with a friend until I understood it. The part I had issues understanding was that every value has to be a node first. That is why we have to store it as an LLnode class. Then we have the wrapper class that can put them together. Linked lists have a front, a back and a size. Each node in the list references another node. It's kind of like a line. The front points to another node, which points to a new node until a node points to the back.
When adding something to the back of the linked list, one must first make the value into a new LLnode. Then, it is important to change the current back so it is pointing to this new node and then set this new node to back. I made the mistake of thinking that we first change the new back to he new node and then change the old back to point to this node. If it was done this way, we would have lost the reference to the old back. Then after all of this hard work, we have to add one to the size of the linked list.
Drawing pictures for these linked lists helped me very much. I was able to visualize exactly where things needed to go and how they should be coded.
No comments:
Post a Comment