Tuesday, February 10, 2015

Abstract Data Types: Stacks and Queues

        Python contains many base data types such as lists, strings, integers, and floats. They are generally universal, but sometimes a modified or completely new data type is needed for a certain scenario. For example, in the case of a queue for a restaurant, a list is a perfectly viable way to sequence the numbers while being mutable, however the proper way to modify the list would be that only the front object can be removed, and objects are added to the queue at the back. These restrictions allow for this queue data type to exist as a modified list. In the case of a stack, one may want to represent a sequence of layers placed upon one another. Once again a list is optimal for representing the sequence, however you would only want to be able to add to, and remove from, the last item in the sequence (removing the bottom/ first totem in a totem pole would be impractical, and the pole would collapse).

No comments:

Post a Comment