This is API for DSDAA

Standard implementations of popular Data Structures Use this package as a reference (role) model for your work.

MyStackException

class dsdaa2.array_stack.MyStackException(mode, max_size, current_size)[source]
MSG_MAP = {0: 'Stack Overflow ;P', 1: 'Stack Empty'}

Handles the Exceptions related to MyStack

msg

str

Depending on the cause, Stack Overflow ;P or Stack Empty

max_size

int

The Max-Container-Size that has been set for this instance.

current_size

int

The # of elements in this instance

MyStack

class dsdaa2.array_stack.MyStack(MAX_SIZE)[source]

A standard Stack Object.

The flexible list container is used to store objects. You can try managing explicitly, the size of the container. It does not have explicit memory management and relies on python‘s Memory Manager and garbage collection.

size[source]

Note

All methods that affect the container size throw REAL python exceptions. Use a try ... except block 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 None

Parameters: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!

isEmpty()[source]
Returns:True if instance is empty (no elements).
Return type:bool
pop()[source]

“pops” the top element of the instance. The instance size decreases 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” value into the Stack.

Parameters:value (object) – The item to be “pushed”.
Returns:True if successful
Return 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.