-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.py
More file actions
39 lines (34 loc) · 834 Bytes
/
Copy pathstack.py
File metadata and controls
39 lines (34 loc) · 834 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
39
class Node:
def __init__(self,value):
self.value = value
self.next = None
class stack:
def __init__(self,value):
new_node = Node(value)
self.top = new_node
self.height=+1
def push(self,value):
new_node=Node(value)
if self.height==0:
self.top=new_node
else:
new_node.next=self.top
self.top=new_node
self.height=+1
def pop(self):
if self.height==0:
return None
temp = self.top
self.top=self.top.next
temp.next = None
self.height-=1
return temp
def print(self):
temp = self.top
while temp is not None:
print(temp.value)
temp=temp.next
my_stack = stack(4)
my_stack.push(5)
my_stack.pop()
my_stack.print()