-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHeapsDemo.java
More file actions
30 lines (28 loc) · 866 Bytes
/
HeapsDemo.java
File metadata and controls
30 lines (28 loc) · 866 Bytes
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
package dsa;
import java.util.Arrays;
public class HeapsDemo {
public static void main(String[] args) {
var heap = new Heaps();
heap.insert(10);
heap.insert(29);
heap.insert(7);
heap.insert(14);
heap.remove();
heap.remove();
heap.insert(6);
heap.insert(9);
System.out.println(heap);
int [] numbers = {10, 4, 6 ,8 ,18, 27, 34, 7, 23};
var heapSort = new Heaps();
for (int items : numbers) {
heapSort.insert(items);
}
for(int i = numbers.length - 1; i >=0; i--){
numbers[i] = heapSort.remove();
}
System.out.println(Arrays.toString(numbers));
MaxHeap.heapify(numbers);
System.out.println(Arrays.toString(numbers));
System.out.println(MaxHeap.getKthLargest(numbers, 2));
}
}