-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathannimal_que.py
More file actions
66 lines (53 loc) · 1.2 KB
/
annimal_que.py
File metadata and controls
66 lines (53 loc) · 1.2 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
59
60
61
62
63
64
from ll import Node
class AnimalNode(Node):
def __init__(self,name=None,data=None):
super(AnimalNode, self).__init__(name,data)
self.next_same_kind = None
class AnimalQueue(object):
def __init__(self):
self.head = None
self.tail = None
self.headc = None
self.tailc = None
self.headd = None
self.taild = None
def enqueue(self,name,kind):
if kind == "cat":
ani_kind = 1
print("cat")
elif kind == "dog":
ani_kind = 2
print("dog")
else:
return False
n = AnimalNode(name,ani_kind)
if self.head == None:
self.head = n
print("head ", self.head.data)
if self.tail != None:
self.tail.next = n
self.tail = n
if ani_kind == 1:
if self.headc == None:
self.headc = n
print("headc ",name)
if self.tailc != None:
self.tailc.next = n
self.tailc = n
if ani_kind == 2:
if self.headd == None:
self.headd = n
print("headd ",name)
if self.taild != None:
self.taild.next = n
self.taild = n
def main():
queue = AnimalQueue()
queue.enqueue("mamut","cat")
queue.enqueue("kara","dog")
queue.enqueue("beyaz","cat")
queue.enqueue("boncuk","cat")
queue.enqueue("kar","dog")
queue.enqueue("zeytin","cat")
if __name__ == "__main__":
main()