forked from ishantk/GW2022PD1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSession13A.py
71 lines (52 loc) · 1.55 KB
/
Session13A.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
class WebPage:
def __init__(self, title, domain, url):
self.title = title
self.domain = domain
self.url = url
self.next = None
self.previous = None
def show(self):
print(self.title, self.domain, self.url)
class Stack:
def __init__(self):
self.head = None
self.tail = None
self.size = 0
print("Stack Created...")
def push(self, page):
self.size += 1
if self.head is None:
self.head = page
self.tail = page
else:
self.tail.next = page
page.previous = self.tail
self.tail = page
def pop(self):
self.size -= 1
temp = self.tail
self.tail = self.tail.previous
self.tail.next = None
del temp
def peek(self, option=1):
if option == 1:
return self.tail
else:
return self.head
def iterate(self):
temp = self.tail
while True:
temp.show()
temp = temp.previous
if temp.previous is None:
temp.show()
break
stack = Stack()
stack.push(WebPage(title="Auribises", domain="www.auribises.com", url="elearning.auribises.com"))
stack.push(WebPage(title="StackOverlflow", domain="www.stackoverflow.com", url="stackoverflow.com/python"))
stack.push(WebPage(title="GoDaddy", domain="www.godaddy.in", url="https://www.godaddy.com/en-in"))
stack.pop()
stack.iterate()
print("SIZE of Stack is:", stack.size)
print("PEEK...")
stack.peek().show()