-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathstack.py
More file actions
40 lines (30 loc) · 846 Bytes
/
Copy pathstack.py
File metadata and controls
40 lines (30 loc) · 846 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
36
37
38
#!/usr/bin/env python
class Stack:
""" simple stack implementation using default list """
def __init__(self, list=None):
if list == None : list = []
self.list = list
def push(self, elem):
self.list.append(elem)
def pop(self):
if self.empty():
raise Exception('Stack is empty !')
else:
return self.list.pop()
def empty(self):
if not len(self.list):
return True
else:
return False
def peek(self):
if self.empty():
raise Exception('Stack is empty')
else:
return self.list[len(self.list) - 1]
def size(self):
if len(self.list):
return len(self.list)
else:
return 0
def show_stack(self):
print self.list