Module pacai.util.stack
A stack data structure.
Expand source code
"""
A stack data structure.
"""
class Stack(object):
"""
A container with a last-in-first-out (LIFO) queuing policy.
"""
def __init__(self):
self.list = []
def push(self, item):
"""
Push an item onto the stack.
"""
self.list.append(item)
def pop(self):
"""
Pop the most recently pushed item from the stack.
"""
return self.list.pop()
def isEmpty(self):
"""
Returns True if the stack is empty.
"""
return len(self.list) == 0
def __len__(self):
return len(self.list)
Classes
class Stack
-
A container with a last-in-first-out (LIFO) queuing policy.
Expand source code
class Stack(object): """ A container with a last-in-first-out (LIFO) queuing policy. """ def __init__(self): self.list = [] def push(self, item): """ Push an item onto the stack. """ self.list.append(item) def pop(self): """ Pop the most recently pushed item from the stack. """ return self.list.pop() def isEmpty(self): """ Returns True if the stack is empty. """ return len(self.list) == 0 def __len__(self): return len(self.list)
Methods
def isEmpty(self)
-
Returns True if the stack is empty.
Expand source code
def isEmpty(self): """ Returns True if the stack is empty. """ return len(self.list) == 0
def pop(self)
-
Pop the most recently pushed item from the stack.
Expand source code
def pop(self): """ Pop the most recently pushed item from the stack. """ return self.list.pop()
def push(self, item)
-
Push an item onto the stack.
Expand source code
def push(self, item): """ Push an item onto the stack. """ self.list.append(item)