-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProcess.cpp
More file actions
34 lines (29 loc) · 1020 Bytes
/
Copy pathProcess.cpp
File metadata and controls
34 lines (29 loc) · 1020 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
#include "Process.h"
#include <iostream>
#include <algorithm>
using namespace std;
Process::Process(const string &n, int p) : name(n), priority(p) {}
string Process::getName() const { return name; }
int Process::getPriority() const { return priority; }
// Process:: means “this function belongs to the Process class.”
// In Process.h, you must first declare it, for example:
// static void sortProcesses(vector<Process>& processes);
// The call must be prefixed with the class name:
// Process::sortProcesses(ps);
void Process::sortProcesses(vector<Process> &processes)
{
sort(processes.begin(), processes.end(),
[](const Process &a, const Process &b)
{
return a.getPriority() < b.getPriority();
});
}
void Process::printProcesses(const vector<Process> &processes)
{
cout << "Process Scheduling:\n";
for (const auto &p : processes)
{
cout << " Running " << p.getName()
<< " (Priority " << p.getPriority() << ")\n";
}
}