-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueueUsingNode.py
More file actions
40 lines (34 loc) · 1.06 KB
/
Copy pathQueueUsingNode.py
File metadata and controls
40 lines (34 loc) · 1.06 KB
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
from Node import Node
class QueueUsingNode(object):
"""description of class"""
def __init__(self):
self.head = None
self.tail = None
def add(self, data):
newNode = Node(data)
if self.head == None :
self.head = newNode
self.tail = newNode
else:
currentNode = self.head
while currentNode.next != None:
currentNode = currentNode.next
self.tail.next = currentNode
self.tail = currentNode
def remove(self):
if self.head == None:
print('No items to remove from the queue')
elif self.head.next == None:
retVal = self.head.data
self.head = None
self.tail = None
return retVal
else:
retVal = self.head.data
self.head = self.head.next
return retVal
def peak(self):
if self.head == None:
print('No items to remove from the queue')
else :
return self.head.data