forked from akkupy/codeDump
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathworstfit.c
66 lines (58 loc) · 1.4 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include<stdio.h>
int main()
{
int np,nb,max=-1,i,j,pos;
printf("enter the no. of processes: ");
scanf("%d",&np);
int ap[np][2];
printf("enter the size of processes: \n");
for(i=0;i<np;i++)
{
printf("p[%d]: ",i+1);
scanf("%d",&ap[i][0]);
ap[i][1]=0;
}
printf("enter the no. of blocks: ");
scanf("%d",&nb);
int ab[nb][3];
printf("enter the size of blocks: \n");
for(i=0;i<nb;i++)
{
printf("b[%d]: ",i+1);
scanf("%d",&ab[i][0]);
ab[i][1]=0;
ab[i][2]=0;
}
for(i=0;i<np;i++)
{
for(j=0;j<nb;j++)
{
if(ap[i][0]<ab[j][0] && ab[j][1]==0)
{
if((ab[j][0]-ap[i][0])>max)
{
max=ab[j][0]-ap[i][0];
pos=j;
}
}
}
if(ap[i][0]<ab[pos][0])
{
ab[pos][1]=i+1;
ab[pos][2]=ap[i][0];
ap[i][1]=1;
max=-1;
pos=0;
}
}
printf("block\tsize\tprocess\tsize\tstatus\n");
for(i=0;i<nb;i++)
{
printf("b[%d]\t\t%d\t\t%d\t\t%d\t\t",i+1,ab[i][0],ab[i][1],ab[i][2]);
if(ab[i][1]==0)
printf("not allocated\n");
else
printf("allocated\n");
}
return 0;
}