-
Notifications
You must be signed in to change notification settings - Fork 0
/
worstfit.c
50 lines (47 loc) · 1.28 KB
/
worstfit.c
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
#include <stdio.h> //verified
int main()
{
int m, n;
int flag, t, largestindex, largestsize;
printf("Enter the no of blocks");
scanf("%d", &m);
int blocks[m];
printf("Enter the sizes of each block");
for (int i = 0; i < m; i++)
{
scanf("%d", &blocks[i]);
}
printf("Enter the no of processes");
scanf("%d", &n);
int process[n], allocation[n];
printf("Enter the size of each processes");
for (int i = 0; i < n; i++)
{
scanf("%d", &process[i]);
allocation[i] = -1;
}
for (int i = 0; i < n; i++)
{
flag = 0;
for (int j = 0; j < m; j++)
{
if (process[i] <= blocks[j])
{
if (flag == 0)
{
largestsize = blocks[j];
largestindex = j;
flag++;
}
else if (blocks[j] >= largestsize)
{
largestsize = blocks[j];
largestindex = j;
}
}
}
t = blocks[largestindex];
blocks[largestindex] = blocks[largestindex] - process[i];
printf("%d %d %d %d\n", i + 1, process[i], largestindex + 1, t);
}
}