else/Stack/README.md

34 lines
1.1 KiB
Markdown
Raw Normal View History

2014-12-03 22:24:01 +00:00
Stack
======
A class to imitate the [Stack](http://en.wikipedia.org/wiki/Stack_(abstract_data_type)) data structure.
class Stack:
Class to replicate a Stack data structure.
Attributes: maxlen, name
2014-12-03 22:38:22 +00:00
Methods: copy, pop, populate, push, top, truncate
2014-12-03 22:24:01 +00:00
2014-12-03 22:38:22 +00:00
def copy(self):
2014-12-03 22:24:01 +00:00
Return a deep copy of this Stack as a new object
def pop(self, count=1):
Pop the last `count` items off of the Stack. Default 1
returns the most recently popped item
def populate(self, itemlist, destructive=False):
Push as many items as possible from `itemlist` onto the Stack
and discard the rest.
2014-12-03 22:41:43 +00:00
if `destructive` is True, the current data will be overwritten
2014-12-03 22:24:01 +00:00
def push(self, item):
2014-12-03 22:41:43 +00:00
Push an item onto the top of the Stack
2014-12-03 22:24:01 +00:00
def top(self):
Return the item on the top of the stack without popping it
def truncate(self, value):
Remove all items from the Stack after index `value`, and set
`maxlen` to `value`, preventing the addition of further items.
returns None