문제가 잘 안풀려서 질문 드립니다.
대나무
질문 제목 : 기억장치 배치 기법제가 만든 프로그램이 맞는건지 확신이 안가서 질문드립니다.
first fit,best fit,worst fit을 프로그래밍하는겁니다.
질문 내용 :
#include stdio.h
typedef struct
{
int useagespace; // 사용 공간
int remainspace; // 남은 공간
}memory;
void firstfit(memory m[], int n, int requestspace)
{
int i=0;
while(i n)
{
if(m[i].remainspace = requestspace)
{
m[i].useagespace += requestspace;
m[i].remainspace -= requestspace;
printf(%d번째 공간에 배치하였습니다.\n, i+1);
return;
}
i++;
}
printf(요청작업을 공간에 배치할수 없습니다.\n);
}
void bestfit(memory m[], int n, int requestspace)
{
int i;
int bestindex = -1;
for(i = 0; i n; i++)
{
if(bestindex == -1)
{
if(m[i].remainspace = requestspace)
bestindex = i;
}
else
{
if(m[i].remainspace = requestspace)
{
if(m[i].remainspace m[bestindex].remainspace)
bestindex = i;
}
}
}
if(bestindex == -1)
printf(요청작업을 공간에 배치할수 없습니다.\n);
else
{
m[bestindex].useagespace += requestspace;
m[bestindex].remainspace -= requestspace;
printf(%d번째 공간에 배치하였습니다.\n, bestindex+1);
}
}
void worstfit(memory m[], int n, int requestspace)
{
int i;
int worstindex = 0;
for(i = 1; i n; i++)
{
if(m[i].remainspace m[worstindex].remainspace)
worstindex = i;
}
if(m[worstindex].remainspace = requestspace)
{
m[worstindex].useagespace += requestspace;
m[worstindex].remainspace -= requestspace;
printf(%d번째 공간에 배치하였습니다.\n, worstindex+1);
}
else
printf(요청작업을 공간에 배치할수 없습니다.\n);
}
void print(memory m[], int n)
{
int i ;
for(i = 0; i n; i++)
{
printf(%d번째 : %2dk 공백 %2dk 사용중\n,i+1, m[i].remainspace, m[i].useagespace);
}
}
void main()
{
int requestspace;
memory m[7] =
{
{ 0, 17 },
{ 10, 0 },
{ 0, 7 },
{ 4, 0 },
{ 0, 15 },
{ 20, 0 },
{ 0, 50 },
}; // 7개의 구역으로 나누었습니다.
print(m, 7);
printf(기억장치 공간 입력 : );
scanf(%d, &requestspace);
firstfit(m, 7, requestspace);
//worstfit(m, 7, requestspace);
//bestfit(m, 7, requestspace);
print(m, 7);
}
이렇게 밖에 안되서 질문드립니다.
이거 말고 다른 방법으로 만들까 하는데 이것도 겨우 만든거라 막막하네요ㅠ