문제가 잘 안풀려서 질문 드립니다.
대나무
질문 제목 : 기억장치 배치 기법제가 만든 프로그램이 맞는건지 확신이 안가서 질문드립니다.
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);
}
이렇게 밖에 안되서 질문드립니다.
이거 말고 다른 방법으로 만들까 하는데 이것도 겨우 만든거라 막막하네요ㅠ
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2693387 | 배열문제입니다 수정오류캡쳐했습니다 (6) | 연하얀 | 2025-05-01 |
2693356 | text 입출력 내림차순 질문입니다 ㅠ | 빛글 | 2025-05-01 |
2693328 | C언어를이용해서 .txt파일 외에 다른 확장자 파일 삭제가 가능한지.. (2) | 대나무 | 2025-05-01 |
2693299 | 파일입출력 바이너리파일 | 독특한 | 2025-04-30 |
2693273 | 오류 (1) | 귀1여운렩 | 2025-04-30 |
2693080 | visual studio 2008 express edition 등록키 말인데요 | 얀별 | 2025-04-28 |
2693053 | 배열, 구조체 관련 프로그래밍 질문드립니다. | 싸리 | 2025-04-28 |
2693025 | 프로그램을 짜봤는데요 ㅠㅠ | 상처입은마음 | 2025-04-28 |
2693001 | 워닝문제, 세그멘트결함문제 (1) | 월식 | 2025-04-28 |
2692979 | 라인한줄 이랑.. 소스 설명좀 부탁드려요.. | 이루리 | 2025-04-27 |
2692947 | 이 문제좀 풀어 주세요..ㅜㅜ (1) | 소리 | 2025-04-27 |
2692889 | 함수의 구조체 인자로 받아서 그 인자로 데이터 넣기... | 한뎃집 | 2025-04-27 |
2692862 | 성적 출력 하는 프로그램인데요~!!!도움좀 주세욤.ㅠ | 두빛나래 | 2025-04-26 |
2692831 | if 문 간단해요 빨리좀 ㅠㅠ | 이플 | 2025-04-26 |
2692805 | 실행파일이 이상해요 | 푸헷 | 2025-04-26 |
2692750 | 퀵정렬 질문이요 . | 동생몬 | 2025-04-25 |
2692700 | 이 소스코드에 문제 있나요?? (2) | 초코초코해 | 2025-04-25 |
2692596 | 오류좀 잡아주세요 | 하나 | 2025-04-24 |
2692510 | 함수형 중에서.. (6) | 한란 | 2025-04-23 |
2692483 | C언어 함수, Header | 떠나간그놈 | 2025-04-23 |