Wednesday, October 30, 2013

Week 7 of Coding

This week was all about linked lists. This is a basic data structure that connects information together. It is very simple and only requires two components to start with: the current data and the data it wants to link to.

``````````````
class Node:
   def __init__(self, data, next):
   self.data = data
   self.next = next
``````````````

One simply may use the algorithm to organize an entire list of data with the sorting method one would like. This is convenient for huge amount of information that are random and troublesome to look into. Also, this huge amount of info may only have little diversity, otherwise after converting into linked lists, the information given would still be random anyways. For example if there is a list of numbers, we want to link each number with the next in non-decreasing value. So the structure would look something like: 1-2-3-4-5-6....

``````````````
1. look into this number_lsit and use the method 'sort' to put in desired order.
2. set current = number_list[0]
3. set next = number_list[1]
4. then number_linked_list = Node(current, next)

this would be the basic structure, all is left is to add a for loop, that for each pair of numbers on index 0&1, 1&2 etc., this linked list adds the values after.
``````````````

No comments:

Post a Comment