/* Freespace */
#include<stdio.h>
struct memory
{
int size;
int empty;
}m[20];
int j[20];
int nm,nj;
void asort();
void dsort();
void fit();
void display(int[]);
main()
{
int i,ch,njx;
printf("enter no of memory slots \n");
scanf("%d",&nm);
printf("enter memory slots");
for(i=0;i<nm;i++)
{
scanf("%d",&m[i].size);
m[i].empty=m[i].size;
}
printf("enter no of jobs\n");
scanf("%d",&nj);
printf("enter the jobs\n");
for(i=0;i<nj;i++)
{
printf("enter the job size of j:%d",i+1);
scanf("%d",&j[i]);
}
printf("various types of placement algorithms\n");
printf("1.first fit\n2.best fit\n3.worst fit\n4.readmore\n5.exit\n");
while(1)
{
place:
printf("enter your choice for placing:");
scanf("%d",&ch);
switch(ch)
{
case 1:fit(ch);
break;
case 2:fit(ch);
break;
case 3:fit(ch);
break;
case 4:printf("enter no of more jobs\n");
scanf("%d",&njx);
i=nj;
nj=njx;
printf("enter the job\n");
for( ;i<nj;i++)
scanf("%d",&j[i]);
goto place;
case 5:exit(0);
default:printf("invalid choice");
}
}
}
void fit(int ch)
{
int i,k;
int jm[20];
struct memory tm[20];
for(i=0;i<nm;i++)
tm[i]=m[i];
for(i=0;i<nj;i++)
{
jm[i]=0;
if(ch==2)
asort();
if(ch==3)
dsort();
for(k=0;k<nm;k++)
{
if(j[i]<m[k].empty)
{
jm[i]=m[k].size;
m[k].empty=j[i];
break;
}
}
}
for(i=0;i<nm;i++)
m[i]=tm[i];
display(jm);
}
void display(int jm[20])
{
int i,k,use,nf;
printf("job placement\n");
for(i=0;i<nj;i++)
{
printf("%d",j[i]);
if(jm[i]!=0)
printf("\t %d",jm[i]);
else
printf("\t can not be placed");
printf("\n");
}
printf("the remaining free slots are\n");
for(i=0;i<nm;i++)
{
for(k=0,use=0;k<nf;k++)
if(jm[k]==m[i].size)
use+=j[k];
printf("%5d",m[i].size-use);
}
printf("\n");
}
void asort()
{
int i,k;
struct memory t;
for(i=0;i<nm;i++)
for(k=0;k<(nm-i-1);k++)
if(m[k].empty>m[k+1].empty)
{
t=m[k];
m[k]=m[k+1];
m[k+1]=t;
}
}
void dsort()
{
int i,k;
struct memory t;
for(i=0;i<nm;i++)
for(k=0;k<(nm-i-1);k++)
if(m[k].empty<m[k+1].empty)
{
t=m[k];
m[k]=m[k+1];
m[k+1]=t;
}
}
I KRISHNAPRASAD PURSUING MY B.TECH IN C.R.REDDY COLLEGE OF ENGINEERING TRADE COMPUTER SCIENCES AND ENGINEERING. I'M HAPPY TO PRESENT ALL TYPE OF PROGRAMS. I HOPE U UTILISE THIS BLOG AND ENJOY YOUR PROGRAMMING. THESE PROGRAMS ARE BEST COMPILED IN TURBO C++ COMPILERS AND SUN JAVA COMPILERS
Thursday, November 25, 2010
FREE SPACE MANAGEMENT
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment