-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStack.py
More file actions
40 lines (37 loc) · 892 Bytes
/
Copy pathStack.py
File metadata and controls
40 lines (37 loc) · 892 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
40
class Element(object):
def __init__(self,value,next=None):
self.value=value
self.next=next
class Stack(object):
def __init__(self, element=None):
self.head=element
def push(self,element):
next_element=self.head
self.head=element
element.next=next_element
def pop(self):
if self.head:
exiting_element=self.head
print(exiting_element.value)
self.head=self.head.next
return exiting_element
else:
return "Linked List is empty."
def is_empty(self):
if self.head:
return False
else:
return True
e1=Element(5)
e2=Element(6)
e3=Element(7)
my_stack=Stack(e1)
my_stack.push(e2)
my_stack.push(e3)
my_stack.pop()
my_stack.pop()
my_stack.pop()
my_stack.pop()
my_stack.push(e1)
my_stack.pop()
my_stack.is_empty()