Pythonã«ã¯ãé åºä»ãã®ãªã¹ãã§ãã¼ããå®è£ ããheapqã¢ã¸ã¥ã¼ã«ãç¨æããã¦ããããã®ã¢ã¸ã¥ã¼ã«ãå©ç¨ãããã¨ã§ãã¢ã¤ãã ã®è¿½å ãåé¤ã®éãã½ã¼ããããç¶æ ãç¶æããããåªå é ä½ä»ããã¥ã¼ãããç´ æ©ãç°¡åã«ä½æãããã¨ãã§ããã®ã§ããããã®heapqã¢ã¸ã¥ã¼ã«ã§ã¯ã常ã«æå°ã®ã¢ã¤ãã ãè¿ããæå°ãã¼ãããå®ç¾ããããã®é¢æ°ãå®ç¾©ããã¦ããã以ä¸ã®ããã«heappushé¢æ°ãç¨ãã¦å¤ã®è¿½å ããheappopé¢æ°ã§å¤ã®åé¤ãè¡ããã >>> from heapq import heappush, heappop >>> heap = [] >>> heappush(heap, 2) >>> heappush(heap, 10) >>> heappush(heap, 4) >>> heappush(heap, 5) >>> heappop(heap) 2 >>> heappop(heap
{{#tags}}- {{label}}
{{/tags}}