-
Notifications
You must be signed in to change notification settings - Fork 0
/
prev
139 lines (126 loc) · 2.97 KB
/
prev
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
* Insert your name and date.
* Insert description of the class.
*/
public class DaryMaxHeap {
// insert your instance variables here
// insert your constants (if any) here
public Integer HeapSize;
private ArrayList<T> array;
private int childLimit;
/*
* Constructor
*
* Initialize instance variables, i.e. create an empty heap
*
* @param n Maximum number of children per tree node, i.e. degree of the tree
* @throws IllegalArgumentException Parameter n is less than or equal to one
*/
public DaryMaxHeap(int n) {
// insert your code here
HeapSize = array.size() - 1;
}
/*
* Check if the heap is empty
*
* @return True if the heap is empty, otherwise false
*/
public boolean isEmpty() {
// replace this with your code
return false;
}
/*
* Size of the heap
*
* @return Number of nodes in the heap
*/
public int size() {
// replace this with your code
return 0;
}
/*
* Height of the heap, i.e. complete n-ary tree
*
* @return Number of edges from root node to farthest leaf node
*/
public int height() {
// replace this with your code
return 0;
}
/*
* Peek at the max element
*
* Retrieves, but does not remove, the max element in the heap
*
* @throws RuntimeException Heap is empty
*/
public int peek()
{
// replace this with your code
return 0;
}
/*
* Add to the heap
*
* Inserts the specified element into this heap.
*
* @param e Element to insert
*/
public void add (int e) {
// insert your code here
}
/*
* Peek at the max element
*
* Retrieves and removes the max element of the heap.
*
* @throws RuntimeException Heap is empty
*/
public int poll() {
// replace this with your code
return 0;
}
/*
* Make the heap empty
*/
public void clear() {
// insert your code here
}
/*
* Array-based representation of the heap
*
* @return An array-based representation in level order (see lecture notes)
* of this max heap.
* If the heap is empty then return an array of length zero.
* This method never returns null.
*/
public int [] toArray() {
// replace this with your code
return null;
}
/*
* Conversion to d-ary min heap
*
* @return An array-based representation in level order of a Min Heap
* containing all the elements in this heap.
* If the heap is empty then return an array of length zero.
* This method never returns null.
*/
public int [] toMinHeap() {
// replace this with your code
return null;
}
/*
* Sort elements in ascending order using the Heap Sort algorithm presented in lecture
*
* @param heap An d-ary max heap
* @return An array of the elements in heap in ascending sorted order.
* If the heap is empty then return an array of length zero.
* This method never returns null.
* @throws IllegalArgumentException Parameter heap is null
*/
public static int [] heapsort(DaryMaxHeap heap) {
// replace this with your code
return null;
}
}