This is API for DSDAA¶
Standard implementations of popular Data Structures Use this package as a reference (role) model for your work.
MyStack¶
-
class
dsdaa2.array_stack.MyStack(MAX_SIZE)[source]¶ A standard Stack Object.
The flexible
listcontainer is used to store objects. You can try managing explicitly, the size of the container. It does not have explicit memory management and relies onpython‘s Memory Manager and garbage collection.Note
All methods that affect the container size throw REAL python exceptions. Use a
try ... exceptblock like this:flipStack = MyStack(7) try: flipStack.pop() except MyStackException as e: print e print e.msg, e.max_size, e.current_size
Warning
Add more “goals” for students here??
-
__init__(MAX_SIZE)[source]¶ All items in the container are initialised to
NoneParameters: MAX_SIZE (int) – size of the container
-
__repr__()[source]¶ Returns a string representation of the Stack Container. If element objects can be represented as strings (
__repr__is defined for them), they will also be printed nicely!
-
pop()[source]¶ “pops” the top element of the instance. The instance
sizedecreases by one (if operation is successful)..Returns: top element if successful Return type: object Raises: MyStackException– if the instance is empty.
-
push(value)[source]¶ “pushes”
valueinto the Stack.Parameters: value (object) – The item to be “pushed”. Returns: Trueif successfulReturn type: bool Raises: MyStackException– if the instance is full (and overflows due to this operation)
-
size()[source]
-
top()[source]¶ Does not change the no. of elements in the instance.
Returns: top element if successful Return type: object Raises: MyStackException– if the instance is empty.
-