|
Revision 423, 0.8 kB
(checked in by cneumann, 2 years ago)
|
changed: - improved formatting of description text for comments
and inclusion into runtime.
- moved description for class Foo into FooBase?.cpp
|
- Property svn:eol-style set to
native
- Property svn:keywords set to
Id
|
| Line | |
|---|
| 1 |
|
|---|
| 2 |
class ListStack: |
|---|
| 3 |
""" A simple stack based implementation based on lists. |
|---|
| 4 |
""" |
|---|
| 5 |
|
|---|
| 6 |
def __init__(self): |
|---|
| 7 |
"""Creates a new empty stack. |
|---|
| 8 |
""" |
|---|
| 9 |
self.m_stack = []; |
|---|
| 10 |
|
|---|
| 11 |
def push(self, obj): |
|---|
| 12 |
"""Adds obj to the top of the stack. |
|---|
| 13 |
""" |
|---|
| 14 |
self.m_stack.append(obj); |
|---|
| 15 |
|
|---|
| 16 |
def pop(self): |
|---|
| 17 |
"""Removes the obj on the top of the stack. |
|---|
| 18 |
""" |
|---|
| 19 |
if not self.empty(): |
|---|
| 20 |
self.m_stack = self.m_stack[:-1]; |
|---|
| 21 |
|
|---|
| 22 |
def top(self): |
|---|
| 23 |
"""Returns the obj on top of the stack. |
|---|
| 24 |
""" |
|---|
| 25 |
return self.m_stack[len(self.m_stack) - 1]; |
|---|
| 26 |
|
|---|
| 27 |
def empty(self): |
|---|
| 28 |
"""Returns True if the stack is empty, False otherwise. |
|---|
| 29 |
""" |
|---|
| 30 |
return len(self.m_stack) == 0; |
|---|
| 31 |
|
|---|
| 32 |
def clear(self): |
|---|
| 33 |
"""Removes all elements from the stack. |
|---|
| 34 |
""" |
|---|
| 35 |
self.m_stack = []; |
|---|
| 36 |
|
|---|