-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayStack.py
More file actions
35 lines (27 loc) · 830 Bytes
/
ArrayStack.py
File metadata and controls
35 lines (27 loc) · 830 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
29
30
31
32
33
34
35
# -*- coding: utf-8 -*-
"""
Spyder Editor
This temporary script file is located here:
/home/akshay/.spyder2/.temp.py
"""
class Empty(Exception):
'''Error attempting to access an element from an empty container.'''
pass
class ArrayStack:
'''LIFO Stack implementation using a Python list as underlying storage.'''
def __init__(self):
self.data = []
def __len__(self):
return len(self.data)
def is_empty(self):
return (len(self.data == 0))
def push(self, e):
return self.data.append(e)
def top(self):
if self.is_empty():
return Empty('Stack is empty')
return self.data[-1]
def pop(self):
if self.is_empty():
return Empty('Stack is empty')
return self.data.pop()