-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStack.py
More file actions
35 lines (28 loc) · 768 Bytes
/
Stack.py
File metadata and controls
35 lines (28 loc) · 768 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
class Stack:
def __init__(self) -> None:
self.stack=[]
self.top=-1
def push(self,val):
if len(self.stack)==0:
self.stack.append(val)
self.top+=1
else:
self.stack.append(val)
self.top+=1
def show_top(self):
if len(self.stack)>0:
return self.stack[self.top]
return None
def pop(self):
if len(self.stack) > 0:
self.top -=1
return self.stack.pop()
return None
def show(self):
print(self.stack)
def is_empty(self):
if len(self.stack) == 0:
return True
return False
def exists(self,val):
return (val in self.stack)