当前位置: 首页>>代码示例>>Python>>正文


Python PriorityQueue.dequeue方法代码示例

本文整理汇总了Python中PriorityQueue.PriorityQueue.dequeue方法的典型用法代码示例。如果您正苦于以下问题:Python PriorityQueue.dequeue方法的具体用法?Python PriorityQueue.dequeue怎么用?Python PriorityQueue.dequeue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PriorityQueue.PriorityQueue的用法示例。


在下文中一共展示了PriorityQueue.dequeue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: shortest_path

# 需要导入模块: from PriorityQueue import PriorityQueue [as 别名]
# 或者: from PriorityQueue.PriorityQueue import dequeue [as 别名]
 def shortest_path(self, target):
     """
     Uses Dijkstra's algorithm to return the shortest paths between the 
     target and all other nodes in the graph.
     """
     if not self.weighted:
         print "Graph is not weighted; redirecting to BFS"
         return self.bfs(target, min_distance=True)
     distances_pq = PriorityQueue("min")
     distances_dict = {} 
     unvisited = []
     for node in self.adj_matrix[0]:
         if node == target:
             distances_pq.enqueue(0, node)
             distances_dict[node] = 0
         elif node != False:
             distances_pq.enqueue(float('inf'), node)
             distances_dict[node] = float('inf')
         else:
             continue
         unvisited.append(node)
     while unvisited:
         min_distance, min_node = distances_pq.dequeue()
         if min_node not in unvisited:
             continue
         neighbors = self.linked(min_node)
         for neighbor in neighbors:
             neighbor_distance = min(distances_dict[neighbor], 
                                     min_distance + self.link_weight(min_node, neighbor))
             if neighbor_distance != distances_dict[neighbor]:
                distances_dict[neighbor] = neighbor_distance
                distances_pq.enqueue(neighbor_distance, neighbor)
         unvisited.remove(min_node)
     return distances_dict
开发者ID:nikrdc,项目名称:Python-Data-Structures-and-Algorithms,代码行数:36,代码来源:Graph.py

示例2: PriorityQueue

# 需要导入模块: from PriorityQueue import PriorityQueue [as 别名]
# 或者: from PriorityQueue.PriorityQueue import dequeue [as 别名]
from PriorityQueue import PriorityQueue

patient1 = [2, "John"]
patient2 = [1, "Jim"]
patient3 = [5, "Tim"]
patient4 = [7, "Cindy"]

priorityQueue = PriorityQueue()
priorityQueue.enqueue(patient1)
priorityQueue.enqueue(patient2)
priorityQueue.enqueue(patient3)
priorityQueue.enqueue(patient4)
    
while priorityQueue.getSize() > 0:
    print(str(priorityQueue.dequeue()), end = " ")
开发者ID:EthanSeaver,项目名称:Python-Projects,代码行数:17,代码来源:TestPriorityQueue.py


注:本文中的PriorityQueue.PriorityQueue.dequeue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。