-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueueList.py
More file actions
executable file
·58 lines (49 loc) · 1.29 KB
/
QueueList.py
File metadata and controls
executable file
·58 lines (49 loc) · 1.29 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python
""" generated source for module Queue """
class Queue(object):
class Node(object):
def __init__(self, v, n=None):
self.value = v
self.next = n
def __init__(self):
self.head = None
self.tail = None
self.count = 0
def size(self):
return self.count
def isEmpty(self):
return (self.head == None)
def peek(self):
if self.isEmpty():
raise RuntimeError("StackEmptyException")
return self.head.value
def add(self, value):
temp = self.Node(value, None)
self.count += 1
if self.head == None:
self.head = self.tail = temp
else:
self.tail.next = temp
self.tail = temp
def remove(self):
if self.isEmpty():
raise RuntimeError("StackEmptyException")
self.count -= 1
value = self.head.value
self.head = self.head.next
return value
def printList(self):
temp = self.head
while temp != None:
print temp.value,
temp = temp.next
q = Queue()
i = 1
while i <= 100:
q.add(i)
i += 1
i = 1
while i <= 50:
q.remove()
i += 1
q.printList()