-
Notifications
You must be signed in to change notification settings - Fork 0
/
bestfit.c
63 lines (47 loc) · 1.1 KB
/
bestfit.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
#include<stdio.h> //verified
int main()
{
int m,n;
int flag,t,leastindex,leastsize;
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)
{
leastsize=blocks[j];
leastindex=j;
flag++;
}
else if(blocks[j]<=leastsize)
{
leastsize=blocks[j];
leastindex=j;
}
}
}
t=blocks[leastindex];
blocks[leastindex]=blocks[leastindex]-process[i];
printf("%d %d %d %d\n",i+1,process[i],leastindex+1,t);
}
}