-
Notifications
You must be signed in to change notification settings - Fork 0
/
first-fit.cpp
47 lines (42 loc) · 1.58 KB
/
first-fit.cpp
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
#include <bits/stdc++.h>
using namespace std;
int main()
{
int hole; // Number of free memory holes
cin >> hole;
vector<int> holes(hole);
for (int i = 0; i < hole; i++)
{
cin >> holes[i]; // Free memory hole's size
}
int size; // Process size
cin >> size;
for (int x: holes)
{
if (x >= size)
{
cout << "The process is allocated into "
<< x << " mb memory hole.";
return 0;
}
}
cout << "No suitable hole available!";
}
/*//... Sample Input-Output:
___________________________________________________________________________________________________________________________________________________________________________________________________________________________
Input:
7
12 3 5 32 43 29 7
27
___________________________________________________________________________________________________________________________________________________________________________________________________________________________
Output:
The process is allocated into 32 mb memory hole.
___________________________________________________________________________________________________________________________________________________________________________________________________________________________
Input:
7
12 3 5 13 4 9 7
14
___________________________________________________________________________________________________________________________________________________________________________________________________________________________
Output:
No suitable hole available!
*///...