-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprobando_node_based_queue.py
More file actions
42 lines (26 loc) · 903 Bytes
/
probando_node_based_queue.py
File metadata and controls
42 lines (26 loc) · 903 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
41
42
from node_based_queue import Queue
food = Queue()
food.enqueue("eggs")
food.enqueue("ham")
food.enqueue("spam")
# Veamos ahora que tenemos en nuestro head de la Queue:
print(food.head.data) # eggs
# ¿Como puedo acceder al proximo elemento de mi lista de nodos?
# Recordemos que no existen indices en las listas enlazadas de nodos.
# Facil:
print(food.head.next.data) # ham
# ¿Y al tercer elemento?
print(food.head.next.next.data) # spam
# Y si la recorremos para atras?
print(food.tail.data) # spam
print(food.tail.previous.data) # ham
print(food.tail.previous.previous.data) # eggs
# contemos cuantos elementos hay:
print(food.count) # 3
# Y si removemos un elemento cual debería salir? "eggs" porque fue el primero en ingresar:
# print(food.dequeue())
# Iterando mi queue de nodos de forma completa:
count = 1
for item in food.iter():
print(f"{count}: {item}")
count += 1