-
Notifications
You must be signed in to change notification settings - Fork 0
/
first fit.c
65 lines (52 loc) · 1.32 KB
/
first fit.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>
void implimentFirstFit(int blockSize[], int blocks, int processSize[], int processes)
{
int allocate[processes];
for(int i = 0; i < processes; i++)
{
allocate[i] = -1;
}
for (int i = 0; i < processes; i++)
{
for (int j = 0; j < blocks; j++) {
if (blockSize[j] >= processSize[i])
{
allocate[i] = j;
blockSize[j] -= processSize[i];
break;
}
}
}
printf("\nProcess No.\tProcess Size\tBlock no.\n");
for (int i = 0; i < processes; i++)
{
printf("%d \t\t\t %d \t\t\t", i+1, processSize[i]);
if (allocate[i] != -1)
printf("%d\n",allocate[i] + 1);
else
printf("Not Allocated\n");
}
}
int main()
{
int blockSize[100];
int processSize[100];
int m,i;
int n;
printf("Enter the size of blocks:");
scanf("%d",&m);
for(i=0;i<m;i++)
{
printf("Enter the block %d:",i+1);
scanf("%d",&blockSize[i]);
}
printf("Enter the size of arriving blocks:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter the block arriving %d:",i+1);
scanf("%d",&processSize[i]);
}
implimentFirstFit(blockSize, m, processSize, n);
return 0;
}