Thursday, March 6, 2014

Week 8: Linked list

Linked list is a new class represented a lists of numbers, just like the linked list below we are looking at.




It has two parts, the first one is value and second one is its contains, which can be regarded as a sub-linkedlist. Every time we add a value to the linked list it will add on the top of it, and just like ADT, the first one to come is the last one to out.

It is really a hard work to find the deepest value, which require us to use recursion algorithm.

But the most attractive function for me in this class is the reverse function.
It can totally reverse the linked list. It is really a challenge if we want to get the deepest value and dig it out on the top.

I have been confused of the whole function for a long time, and finally figure out how it works.


















As we can see, it builds a new linked list and make it equivalent to the original one, and builds a new variable named new_node to do the recursion.

It is such an amazing way to deal with that problem.

1 comment:

  1. just for reminding that there are two ways of representing linkedlist. one is like you say, linkednode, the other is a listlist.

    ReplyDelete