Friday, February 12, 2016

Week 5 More on Stack, Queue, and Linked List


We have discussed linked-list, stack, and queue last week. For queue and stack, we completed classes based on python built-in ADT, list. However, when popping the first item from the queue, because of the shortage of the list, we have to move other items one position ahead, which will cost extra work. The same situation also occurs when we try to add one item at the beginning of the queue.

Therefore, after studying Linked-list, this week we use the linked-list to represent the Stack or Queue.
For Stack, the prepend could be represented as:

For Queue, the pop front could be represented as:

No comments:

Post a Comment