File tree Expand file tree Collapse file tree 1 file changed +19
-1
lines changed
yoonexample/src/main/java/heap Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -39,7 +39,25 @@ public void insert(E data, int priority) {
39
39
40
40
@ Override
41
41
public E delete () {
42
- return null ;
42
+ int rootIndex = 1 ;
43
+ E retData = this .heapArr [rootIndex ].data ; // 루트노드에 존재하던 데이터
44
+ HeapElement <E > lastElement = this .heapArr [this .numOfData ]; // 마지막 노드
45
+
46
+ int parentIndex = rootIndex ; // 루트로 옮기는 것을 의미
47
+ int childIndex = getHighPrioirtyChildIndex (parentIndex ); // 더 우선순위인 자식노드
48
+
49
+ while (childIndex > 0 ) { // 부모노드가 단말노드가 아니라면
50
+ if (lastElement .priority <= this .heapArr [childIndex ].priority ) { // 마지막 노드가 우선순위가 높다면
51
+ break ;
52
+ }
53
+ this .heapArr [parentIndex ] = this .heapArr [childIndex ]; // 자식 노드와 부모노드의 위치를 변경
54
+ parentIndex = childIndex ;
55
+ childIndex = getHighPrioirtyChildIndex (parentIndex );
56
+ }
57
+
58
+ this .heapArr [parentIndex ] = lastElement ; // 마지막에 위치했던 노드를 한 번에 옮긴다.
59
+ this .numOfData -= 1 ;
60
+ return retData ;
43
61
}
44
62
45
63
/**
You can’t perform that action at this time.
0 commit comments