Something we started last week and we carried on with this week was LinkedList (LL). LL is very similar to Trees but a lot more difficult to traverse if not initialized properly. The difference between LLs and Trees are that Trees have any amount of children which then in turn have more children or none at all. LLs on the other hand have only one child and that child in a LL which has another child. So in Trees, different routes take you to different nodes but in LLs, there's only one route. One advantage a LL has is that it allows efficient insertion or removal of elements from any position without reallocation of the structure. This is only if you've made the LL in a certain way, which we learned this week.To be able to traverse the LL properly, you need to initiate a namespace which allows you to keep track of the front of the list as more nodes are added on and also you need to keep track of the length of the list. This will help when you need to find a specific area of the LL so that you can manipulate that section however you need to.
After that we learnt something which was pretty useful. That was that if you want to use write a method for a special function which doesn't allow any parameters (such as __str__) then you can write a separate function which does what you need it to do to represent the info in the manner of a string. Then, once you've written that, you'll be able to call upon that function inside the __str__ function. Even though this idea is quite simple, it never crossed my mind and will prove to be useful in the future.
This week in lab we had to do some more work with LLs. It was pretty straightforward and my partner and I finished in about 40 minutes. We just sat there for the next one and a half hours finishing off extras from the lab handout. After that we started talking about the A2 part 1 and I helped him realize that the code he was working on was for part 2 and part 1 was much simpler than he had anticipated. He was irritated that he had misunderstood the assignment part 1 but was optimistic at the fact that he wouldn't need to worry too much about part 2.
So that's a little insight on LLs. Until next time.

No comments:
Post a Comment