-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCLASS NODE.py
39 lines (36 loc) · 932 Bytes
/
CLASS NODE.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
31
32
33
34
35
36
37
38
39
class Node:
def _init_(self,data):
self.data=data
self.next=None
class stack:
def _init_(self):
self.head=None
def is_empty(self):
return self.head is None
def push(self,data):
new_node=Node(data)
new_node.next=self.head
self.head=new_node
def pop(self):
if self.is_empty():
return None
popped=self.head.data
self.head=self.head.next
return popped
def peek(self):
if self.is_empty():
return None
return self.head.data
def display(self):
current=self.head
while current:
print(current.data,end="->")
current=current.next
print("None")
stack=stack()
stack.push(1)
stack.push(2)
stack.push(3)
stack.display()
print("popped:",stack.pop())
print("peek:",stack.peek())