forked from clair3st/Data-Structures
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.py
More file actions
28 lines (19 loc) · 688 Bytes
/
stack.py
File metadata and controls
28 lines (19 loc) · 688 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"""Stack implementation in Python."""
from linked_list import LinkedList
class Stack(object):
"""Implementation of Stack.
public methods:
push(value) - Adds a value to the stack.
The parameter is the value to be added to the stack.
pop() - Removes a value from the stack and returns that value.
If the stack is empty, attempts to call pop should raise an exception.
"""
def __init__(self, data=None):
"""Initialization."""
self._stack = LinkedList(data)
def push(self, val):
"""Add val to the stack."""
self._stack.push(val)
def pop(self):
"""Remove item off the stack."""
self._stack.pop()