Sunday, March 16, 2014

LinkedList

Recently we learned a new type of list called LinkedList. Different from normal list class, it is a array of nodes which has only one value and the only child is the next  LinkedList's address.

In ordinary NestedList object, it is construct with recursive layers and each layer contains a value and a NestedList. However, this LinkedList provides us a new way to store similar information but in a more flatter way. As each node only have one child, we don't need to consider the size of the next layer. The only thing we need to to is check the value of each node one by one. LinkedList is just like a train with multiple storages. We put our data, here it is 'goods', in this linear order.

Also there are different ways to build this LinkedList object. One way is just like how we built the Tree object but only contains one child. The second one is using a wrapper thought. In this method, we need first build a LinkedNode class which is just like each storage on the train. Secondly we build the LinkedList on the LinkedNode. Therefore the LinkedList to LikedNodes is just like train to several storages. This path provides us better way to implement functions like reverse().

No comments:

Post a Comment