-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.py
More file actions
35 lines (29 loc) · 676 Bytes
/
stack.py
File metadata and controls
35 lines (29 loc) · 676 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 Newnode:
def __init__(self, data):
self.data = data
self.next = None
class Stack:
def __init__(self):
self.head = None
def push(self, item):
node = Newnode(item)
node.next = self.head
self.head = node
def pop(self):
temp = self.head
self.head = self.head.next
temp = None
def isEmpty(self):
if self.head==None:
return 1
return 0
def peek(self):
if(self.isEmpty()==1):
return 1
return self.head.data
stk = Stack()
stk.push(10)
stk.push(8)
stk.push(12)
stk.pop()
print(stk.peek())