Skip to content

Commit 47dd20a

Browse files
authored
WORST FIT
1 parent 88f621a commit 47dd20a

File tree

1 file changed

+51
-0
lines changed
  • Dynamic Partitioning Placement Algorithms

1 file changed

+51
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
//WORST FIT
2+
3+
#include<stdio.h>
4+
#include<conio.h>
5+
#define max 25
6+
void main()
7+
{
8+
int frag[max],b[max],f[max],i,j,nb,nf,temp,highest=0;
9+
static int bf[max],ff[max];
10+
printf("\n\tMemory Management Scheme - Worst Fit");
11+
printf("\nEnter the number of blocks:");
12+
scanf("%d",&nb);
13+
printf("Enter the number of files:");
14+
scanf("%d",&nf);
15+
printf("\nEnter the size of the blocks:-\n");
16+
for(i=1;i<=nb;i++)
17+
{
18+
printf("Block %d:",i);
19+
scanf("%d",&b[i]);
20+
}
21+
printf("Enter the size of the files :-\n");
22+
for(i=1;i<=nf;i++)
23+
{
24+
printf("File %d:",i);
25+
scanf("%d",&f[i]);
26+
}
27+
for(i=1;i<=nf;i++)
28+
{
29+
30+
for(j=1;j<=nb;j++)
31+
{
32+
if(bf[j]!=1) //if bf[j] is not allocated
33+
{
34+
temp=b[j]-f[i];
35+
if(temp>=0)
36+
if(highest<temp)
37+
{
38+
ff[i]=j;
39+
highest=temp;
40+
}
41+
}
42+
}
43+
frag[i]=highest;
44+
bf[ff[i]]=1;
45+
highest=0;
46+
}
47+
printf("\nFile_no:\tFile_size :\tBlock_no:\tBlock_size:\tFragement");
48+
for(i=1;i<=nf;i++)
49+
printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d",i,f[i],ff[i],b[ff[i]],frag[i]);
50+
getch();
51+
}

0 commit comments

Comments
 (0)