forked from marcin-osowski/igc_lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Stack.py
30 lines (30 loc) · 848 Bytes
/
Stack.py
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
class Stack:
def __init__(self):
self.stackList=[]
self.stackSize=0
def push(self,item):
self.stackList.append(item)
self.stackSize+=1
def pop(self):
try:
if self.stackSize==0:
raise Exception("Stack is Empty, returning None")
temp=self.stackList.pop()
self.stackSize-=1
return temp
except Exception as e:
print(str(e))
def size(self):
return self.stackSize
def isEmpty(self):
if self.stackSize==0:
return True
else:
return False
def top(self):
try:
if self.stackSize==0:
raise Exception("Stack is Empty, returning None")
return self.stackList[-1]
except Exception as e:
print(str(e))