[ 파이썬 우선순위 큐 1]

from queue import PriorityQueue  

que = PriorityQueue()    #우선순위 큐 생성 크기=무한대

que.put(5)   #원소 추가
que.put(8)
que.put(1)
que.put(9)
que.put(3)

# 원소 삭제 - 아무것도 지정하지 않고 그냥 get()메서드를
# 사용하면 오름차순으로 정렬되어 있는 원소들이 삭제한다.

#출력하고 원소 삭제
print(que.get())
print(que.get()) 
print(que.get())
print(que.get())

print("que.qsize() = ",que.qsize())   #큐의 크기 확인
print("que.empty() : ",que.empty())  #False

print(que.get())
print("que.qsize() = ",que.qsize())   #큐의 크기 확인
print("que.empty() : ",que.empty())  #True

 

[ 파이썬 우선순위 큐 2]

from queue import PriorityQueue  

que = PriorityQueue(maxsize=10)  #크기 지정

que.put(5)   #원소 추가
que.put(8)
que.put(1)
que.put(9)
que.put(3)


while not que.empty():
    print(que.get())

print("full() : ", que.full())

 

[ 파이썬 우선순위 큐 3 ]

from queue import PriorityQueue 

que = PriorityQueue(maxsize=10)  #크기 지정

#(우선순위,값)으로 원소 추가
que.put((3,2))   
que.put((2,32))
que.put((1,3))
que.put((3,9))   
que.put((2,5))
que.put((4,3))
que.put((3,12))   
que.put((2,25))
que.put((1,13))
que.put((2,1))

print("full() : ", que.full())  #True

# 원소 삭제 
while not que.empty():
    print(que.get())

 

[ 문제1 ] 11279번: 최대 힙 (acmicpc.net)

 

11279번: 최대 힙

첫째 줄에 연산의 개수 N(1 ≤ N ≤ 100,000)이 주어진다. 다음 N개의 줄에는 연산에 대한 정보를 나타내는 정수 x가 주어진다. 만약 x가 자연수라면 배열에 x라는 값을 넣는(추가하는) 연산이고, x가 0

www.acmicpc.net

 

Posted by 명문코딩컴퓨터
,