-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwf.c
More file actions
71 lines (63 loc) · 1.42 KB
/
Copy pathwf.c
File metadata and controls
71 lines (63 loc) · 1.42 KB
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
67
68
69
70
71
#include <stdio.h>
void worstFit(int blockSize[],int m,int processSize[],int n)
{
int allocation[n];
for(int i=0;i<n;i++)
{
allocation[i] = -1;
}
for(int i=0;i<n;i++)
{
int worstIndex=-1;
for(int j=0;j<m;j++)
{
if(blockSize[j]>=processSize[i])
{
if(worstIndex==-1)
{
worstIndex=j;
}
else if(blockSize[worstIndex]<blockSize[j])
{
worstIndex=j;
}
}
}
if(worstIndex!=-1)
{
allocation[i]=worstIndex;
blockSize[worstIndex] -= processSize[i];
}
}
printf("\nProcess\t\tdataSize\t\tallocated\t\tfragments\n");
for(int i = 0; i <n;i++)
{
printf("%d\t\t%d\t\t\t",i+1,processSize[i]);
if(allocation[i]==-1)
{
printf("Not allocated\n");
}
else{
printf("%d\t\t\t%d\n",allocation[i]+1,blockSize[i]);
}
}
}
int main()
{
int m,n,blockSize[10],ProcessSize[10];
printf("Enter the number of Blocks: ");
scanf("%d",&m);
printf("Enter the Block sizes of each: ");
for(int i=0; i<m; i++)
{
scanf("%d",&blockSize[i]);
}
printf("Enter the number of processes: ");
scanf("%d",&n);
printf("Enter the Process size of each: ");
for(int i=0; i<n; i++)
{
scanf("%d",&ProcessSize[i]);
}
worstFit(blockSize,m,ProcessSize,n);
}