라이브러리
[PHP] DsPriorityQueue::allocate - 필요한 용량에 충분한 메모리를 할당합니다.
PHP 에서 DsPriorityQueue::allocate은 Priority Queue의 메모리 할당을 위한 메서드입니다.
DsPriorityQueue::allocate
DsPriorityQueue::allocate은 Priority Queue의 메모리 할당을 위한 메서드입니다. 이 메서드는 Priority Queue의 크기를 지정하고, 할당된 메모리를 초기화합니다.
# 예제
#hostingforum.kr
php
use DsPriorityQueue;
// Priority Queue 생성
$pq = new PriorityQueue();
// 할당된 메모리 크기 지정
$pq->allocate(10);
// 데이터 추가
$pq->insert(5, 5);
$pq->insert(10, 10);
$pq->insert(1, 1);
$pq->insert(8, 8);
$pq->insert(3, 3);
// 우선순위 큐의 데이터 출력
while (!$pq->isEmpty()) {
echo $pq->extract() . "
";
}
# 설명
- `DsPriorityQueue` 클래스의 인스턴스를 생성합니다.
- `allocate` 메서드를 호출하여 할당된 메모리 크기를 10으로 지정합니다.
- `insert` 메서드를 호출하여 데이터를 추가합니다.
- `extract` 메서드를 호출하여 우선순위 큐의 데이터를 추출하고 출력합니다.
# 참고
- `allocate` 메서드는 할당된 메모리 크기를 지정할 때 사용됩니다.
- `insert` 메서드는 데이터를 추가할 때 사용됩니다.
- `extract` 메서드는 우선순위 큐의 데이터를 추출할 때 사용됩니다.
- `isEmpty` 메서드는 우선순위 큐가 비어있는지 확인할 때 사용됩니다.
DsPriorityQueue::deallocate
DsPriorityQueue::deallocate은 Priority Queue의 메모리 해제를 위한 메서드입니다.
# 예제
#hostingforum.kr
php
use DsPriorityQueue;
// Priority Queue 생성
$pq = new PriorityQueue();
// 할당된 메모리 크기 지정
$pq->allocate(10);
// 데이터 추가
$pq->insert(5, 5);
$pq->insert(10, 10);
$pq->insert(1, 1);
$pq->insert(8, 8);
$pq->insert(3, 3);
// 우선순위 큐의 데이터 출력
while (!$pq->isEmpty()) {
echo $pq->extract() . "
";
}
// 할당된 메모리 해제
$pq->deallocate();
# 설명
- `DsPriorityQueue` 클래스의 인스턴스를 생성합니다.
- `allocate` 메서드를 호출하여 할당된 메모리 크기를 10으로 지정합니다.
- `insert` 메서드를 호출하여 데이터를 추가합니다.
- `extract` 메서드를 호출하여 우선순위 큐의 데이터를 추출하고 출력합니다.
- `deallocate` 메서드를 호출하여 할당된 메모리를 해제합니다.
# 참고
- `deallocate` 메서드는 할당된 메모리를 해제할 때 사용됩니다.
- 할당된 메모리를 해제하면 Priority Queue의 데이터는 더 이상 접근할 수 없습니다.
-
- 나우호스팅 @pcs8404
-
호스팅포럼 화이팅!
댓글목록
등록된 댓글이 없습니다.