문제가 잘 안풀려서 질문 드립니다.
대나무
질문 제목 : 기억장치 배치 기법제가 만든 프로그램이 맞는건지 확신이 안가서 질문드립니다.
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);
}
이렇게 밖에 안되서 질문드립니다.
이거 말고 다른 방법으로 만들까 하는데 이것도 겨우 만든거라 막막하네요ㅠ
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2700368 | if에 관해서 질문이요... | Orange | 2025-07-04 |
2700339 | 이거 결과값이 왜이런건지.. (4) | 그댸와나 | 2025-07-04 |
2700313 | 파일 읽어서 저장하는데 빈파일일 경우 문재가 발생하네요.. (2) | 크나 | 2025-07-03 |
2700287 | 구조체 동적할당 연습을 하는데 오류가 뜹니다...(해결) (3) | 아련나래 | 2025-07-03 |
2700264 | 문자와 숫자 동시에 입력??? | 글고운 | 2025-07-03 |
2700236 | txt파일로만 쓰고 읽게 하려면 어떻게 해야 하나요..?? (8) | 미국녀 | 2025-07-03 |
2700211 | 전위 연산자 (2) | 어른처럼 | 2025-07-02 |
2700183 | C에서 파일이름을 받고, 그 파일의 사이즈를 출력해줘야하는데 내용이 출력이 안되네요 ;ㅅ; | 피스케스 | 2025-07-02 |
2700150 | 꼭좀 도와주세요ㅠㅠㅠ | 호습다 | 2025-07-02 |
2700095 | 연산문제...질문... | 오빤테앵겨 | 2025-07-01 |
2700070 | while문 , 3의배수 출력하는 프로그램좀 짜주세욤. | 횃불 | 2025-07-01 |
2700041 | 초보인데요 ㅎ 배열안에 배열을 집어넣을수 있나요?? | 헛장사 | 2025-07-01 |
2700012 | 배열// (1) | 전갈자리 | 2025-07-01 |
2699895 | 무한루프에 빠집니다.!! 해결좀부탁드려요 (10) | 선아 | 2025-06-30 |
2699842 | 질문을 너무 많이 하네여.....죄송.... (2) | 해님꽃 | 2025-06-29 |
2699816 | 오류 질문입니다.. (1) | 해비치 | 2025-06-29 |
2699763 | 질문입니다 ! 꼭 좀 도와주세요ㅠㅠ (2) | 미라 | 2025-06-28 |
2699555 | c언어 다항식을 입력을 했는데 왜 출력이 안될까요? | 피스케스 | 2025-06-27 |
2699528 | C언어 포인터연산 질문입니다. (3) | 안녕나야 | 2025-06-26 |
2699476 | 끌어올림;;달력 짜봤는데요 이 소스 줄일 수 있나요? - 스샷첨부 (2) | 클라우드 | 2025-06-26 |