-
Notifications
You must be signed in to change notification settings - Fork 1
/
priority.js
79 lines (68 loc) · 1.86 KB
/
priority.js
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
const Priority = () => {
btn_Priority.addEventListener("click", run_Priority);
};
const run_Priority = () => {
let Queue = [
{
arriveTime: Number(p1_value[0].value),
burst: Number(p1_value[1].value),
priority: Number(p1_value[2].value),
wait: 0,
fromWho: 0,
},
{
arriveTime: Number(p2_value[0].value),
burst: Number(p2_value[1].value),
priority: Number(p2_value[2].value),
wait: 0,
fromWho: 0,
},
{
arriveTime: Number(p3_value[0].value),
burst: Number(p3_value[1].value),
priority: Number(p3_value[2].value),
wait: 0,
fromWho: 0,
},
];
let arriveQueue = Queue.slice();
//우선순위 높은 순서
Queue.sort((a, b) => {
if (a.priority > b.priority) return 1;
if (a.priority < b.priority) return -1;
return 0;
});
//도착시간 짧은 순서
arriveQueue.sort((a, b) => {
if (a.arriveTime > b.arriveTime) return 1;
if (a.arriveTime < b.arriveTime) return -1;
return 0;
});
let currentTime = arriveQueue[0].arriveTime;
//우선순위와 도착시간 종합한 스케줄링 큐
let schdQ = [];
for (i = 0; i < Queue.length; i++) {
//기다려야할때 다른걸로 넘어간다
if (currentTime < Queue[i].arriveTime) {
for (j = i + 1; j < Queue.length; j++) {
//제일짧은거 찾음
if (currentTime >= Queue[j].arriveTime) {
currentTime += Queue[j].burst;
schdQ.push(Queue[j]);
Queue.splice(j, 1);
i--;
}
}
} else {
currentTime += Queue[i].burst;
schdQ.push(Queue[i]);
Queue.splice(i, 1);
i--;
}
}
for (i = 0; i < schdQ.length; i++) schdQ[i].fromWho = i;
currentTime = schdQ[0].burst + schdQ[0].arriveTime;
schdQ = waitTime(currentTime, schdQ);
result1(schdQ, currentTime, "Priority");
};
Priority();