File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed
sandbox/src/main/java/com/cipher/data_structure/G_Heap_and_Priority_Queue Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change 1+ package com .cipher .data_structure .G_Heap_and_Priority_Queue ;
2+
3+ import com .cipher .data_structure .A_Arrays .Array ;
4+
5+ /**
6+ * @Author: CipherCui
7+ * @Description:
8+ * @Date: Created in 13:33 2018/11/9
9+ */
10+ public class MaxHeap <E extends Comparable > {
11+
12+ private Array <E > data ;
13+
14+ public MaxHeap () {
15+ data = new Array <>();
16+ }
17+
18+ public MaxHeap (int capacity ) {
19+ data = new Array <>(capacity );
20+ }
21+
22+ public int getSize () {
23+ return data .getSize ();
24+ }
25+
26+ public boolean isEmpty () {
27+ return data .isEmpty ();
28+ }
29+
30+ private int parent (int index ) {
31+ if (index == 0 ) {
32+ throw new IllegalArgumentException ("doesn't have parent" );
33+ }
34+ return (index - 1 ) / 2 ;
35+ }
36+
37+ private int leftChild (int index ) {
38+ return index * 2 + 1 ;
39+ }
40+
41+ private int rightChild (int index ) {
42+ return index * 2 + 2 ;
43+ }
44+
45+ }
You can’t perform that action at this time.
0 commit comments