Stack

class pydatastructs.Stack(implementation='array', **kwargs)

Representation of stack data structure

Parameters
  • implementation (str) – Implementation to be used for stack. By default, ‘array’ Currently only supports ‘array’ implementation.

  • items (list/tuple) – Optional, by default, None The inital items in the stack. For array implementation.

  • dtype (A valid python type) – Optional, by default NoneType if item is None, otherwise takes the data type of DynamicOneDimensionalArray For array implementation.

Examples

>>> from pydatastructs import Stack
>>> s = Stack()
>>> s.push(1)
>>> s.push(2)
>>> s.push(3)
>>> str(s)
'[1, 2, 3]'
>>> s.pop()
3

References

1

https://en.wikipedia.org/wiki/Stack_(abstract_data_type)

push(*args, **kwargs)
pop(*args, **kwargs)
property is_empty
property peek
__module__ = 'pydatastructs.miscellaneous_data_structures.stack'