-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPriorityQueue.java
More file actions
35 lines (25 loc) · 951 Bytes
/
PriorityQueue.java
File metadata and controls
35 lines (25 loc) · 951 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
31
32
33
34
35
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Date;
public class PriorityQueue {
static volatile int min = Integer.MAX_VALUE;
BinaryTree tree;
public PriorityQueue(int processes){
tree = new BinaryTree(processes);
}
public boolean insert(int processID, int value){
System.out.println("Inserting " + value + " for process " + processID);
LocalDateTime now = LocalDateTime.now();
int timeStamp = ((now.getDayOfMonth() - 1) * 24 + now.getHour()) * 60 + now.getMinute();
int valueWithTimestamp = timeStamp ^ (value << 16);
return tree.insertIntoTree(processID, valueWithTimestamp);
}
public boolean delete(int processID){
System.out.println("Removing value for process " + processID);
return tree.deleteFromTree(processID);
}
public int findMin(){
return tree.minValue();
}
}