Wednesday, February 3, 2016

Week 4

At the end of last week, we discussed the use of abstract data type (ADT) and a particular 
Stack class as a popular case. This is a great way to visualize how the code should work the best way without telling how to implement codes. For the Stack class, for example, it creates a stack of items and use method of push, add, remove, pop to edit the list and use is_empty to check the emptiness. The stack class usually fulfills the conception of first in last out, or first in first out. This is a generally fascinating idea that I never encountered when I used Java.

During the tutorial, we practiced inheritance and I had a good idea about the parent and children classes.  


Moreover, we talked about balancing parentheses and we define a string with no parenthesis or with corresponding parentheses as balanced. To check the balance of parentheses, we can very well use the stack class we learnt last week. For instance, using this method


st=Stack
for c in s:
    if c not in '(){}[]':
      pass    
    elif c in '({[':
        st.add(c)
    elif not st.is_empty():
        c2=st.remove()
        if((c==')' and not c2=='(') or (c=='}' and not c2=='{') or\
                            (c==']' and not c2=='[')):
            return False    
    else:
        return False

At the second half of the week 4 class, we studied how the linked list works. Linked lists and 
the use of nodes are complements to other tracking methods because they conserve the 
memory for the current position and all node needs is a reference name and a simple value. 
In each Node class, we just give a prevnode, nextnode and the node value. For instance, 
if we create a n1=Node (1) and a n2=Node (2), by setting n2=n1.nextnode, we successfully 
connected the two nodes. 
The difficulty I have is that I write code way too slowly and it took my entire time to write the 
quiz. I need to practice more to get hands and brain speedy.
In short, the class this week taught a great deal of good stuff and I am looking forward into it.

No comments:

Post a Comment