-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathheader.h
74 lines (68 loc) · 1.46 KB
/
header.h
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
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
using namespace std;
class process {
private:
int id;
int burstTime;
int arrival;
vector <pair<int, int>> process_exc;
public:
process() {
id = ID;
ID++;
}
void get_data() {
cout << "please enter the burst time:";
cin >> this->burstTime;
cout << "please enter the arrival time:";
cin >> this->arrival;
}
bool operator< (process& other) {
return (this->arrival < other.arrival);
}
bool operator<= (const process& other) {
return (this->arrival < other.arrival);
}
void decreament() {
burstTime--;
}
void print() {
cout << "ID: " << id << endl;
cout << "burst time: " << burstTime << " arrival time: " << arrival << endl;
}
int getArrival()const { return arrival; }
int getBurst() const { return burstTime; }
int getId()const { return id; }
void setArrival(int val) { arrival = val; }
void setBurst(int val) { burstTime = val; }
static int ID;
};
class Queue {
private:
int layer;
int qTime;
queue<process> q;
public:
Queue(int layer) {
this->layer = layer;
if (layer == 1)
qTime = 8;
else if (layer == 2)
qTime = 16;
}
void push(process p) {
q.push(p);
}
void excute() {
if (q.empty()) throw ("the queue is empty !!!!");
}
};
struct Compare {
bool operator()(process const& p1, process const& p2) {
return p1.getArrival() > p2.getArrival();
}
};