-
Notifications
You must be signed in to change notification settings - Fork 0
/
worstfit.c
65 lines (49 loc) · 822 Bytes
/
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <stdio.h>
#include <stdlib.h>
int main()
{
int p[20], b[20], i, j, np, nb, highest = 0, temp;
int barr[20] = {0}, parr[20] = {0};
printf("Enter the no. of blocks:\n");
scanf("%d",&nb);
printf("Enter the no. of processes:\n");
scanf("%d",&np);
for(i=1;i<=nb;i++)
scanf("%d",&b[i]);
for(i=1;i<=np;i++)
scanf("%d",&p[i]);
for(i=1;i<=np;i++)
{
for(j=1;j<=nb;j++)
{
if(barr[j] == 0)
{
temp = b[j] - p[i];
if(temp >= 0)
{
if(highest <= temp)
{
highest = temp;
parr[i] = j;
}
}
}
}
highest = 0;
barr[parr[i]] = 1;
}
for(i=1;i<=np;i++)
{
if(parr[i] == 0)
{
printf("Process %d Not Allocated\n", i);
}
}
for(i=1;i<=np;i++)
{
if(parr[i] != 0)
printf("%d -> %d\n",p[i],b[parr[i]]);
}
printf("\n");
return 0;
}