-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStack.py
More file actions
35 lines (25 loc) · 674 Bytes
/
Copy pathStack.py
File metadata and controls
35 lines (25 loc) · 674 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
#Node class
class Node:
def __init__(self,data):
self.data = data
self.next = None
class Stack:
def __init__(self) -> None:
self.top == None
def push(self, data):
new_node = Node(data)
if self.top:
new_node.next = self.top
def pop(self):
if self.top is None:
return None
else:
popped_node = self.top
self.top = self.top.next
popped_node.next = None
return popped_node.data
def peek(self):
if self.top:
return self.top.data
else:
return None