Friday, March 13, 2015

Week9-Review on Stack and Queue

I just realized that more than half of the term is completed!!! Among all the topics we covered, I consider Stack and Queue to be the two easiest one for me.  I love this topic because every step of only does one job. It is different from other topics such as recession which we need to complete repeated calculation for one single method. Even though Queue works according to the rule of 'first in first out' and Stack is 'first in last out', there is a great similarity between the fundamental steps of building a Queue and Stack. I am going to decompose the basic steps of a typical Stack and Queue class in this blog. 


So, for the first step, we initialize a Stack or Queue to be empty.










 The second step is to add an object the end of the Stack or Queue

After all objects are added, we can remove them one by one. For Stack, we always remove the last object, and for Queue, we remove the first one.   



 



 

Finally, we ask ourselves whether all the objects are removed from the Stack and Queue. This step is the same for both classes.



 



















No comments:

Post a Comment