Insert an item with the given priority. Args: item: The value to insert. priority: Priority value; defaults to the item itself.
(self, item: Any, priority: Any = None)
| 86 | return len(self.priority_queue_list) |
| 87 | |
| 88 | def push(self, item: Any, priority: Any = None) -> None: |
| 89 | """Insert an item with the given priority. |
| 90 | |
| 91 | Args: |
| 92 | item: The value to insert. |
| 93 | priority: Priority value; defaults to the item itself. |
| 94 | """ |
| 95 | priority = item if priority is None else priority |
| 96 | node = PriorityQueueNode(item, priority) |
| 97 | for index, current in enumerate(self.priority_queue_list): |
| 98 | if current.priority < node.priority: |
| 99 | self.priority_queue_list.insert(index, node) |
| 100 | return |
| 101 | self.priority_queue_list.append(node) |
| 102 | |
| 103 | def pop(self) -> Any: |
| 104 | """Remove and return the item with the lowest priority. |