문제가 잘 안풀려서 질문 드립니다.
대나무
질문 제목 : 기억장치 배치 기법제가 만든 프로그램이 맞는건지 확신이 안가서 질문드립니다.
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);
}
이렇게 밖에 안되서 질문드립니다.
이거 말고 다른 방법으로 만들까 하는데 이것도 겨우 만든거라 막막하네요ㅠ
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2698909 | 서비스 요청 고객 관리 프로그램 짜는것좀 도와주세요ㅜㅜ (4) | 궁수자리 | 2025-06-21 |
2698882 | 프로그래밍좀 짜주세요 (3) | 황예 | 2025-06-21 |
2698855 | 카프-라빈 알고리즘 코딩 분석좀 도와주세요.. | 꽃봄 | 2025-06-20 |
2698829 | 학점계산기 (7) | MyWay | 2025-06-20 |
2698782 | 기초적인 함수 질문이요ㅠㅠㅠㅠ | 내담 | 2025-06-20 |
2698749 | 프로그램 짜던 도중 패닉입니다...ㅜ | 파랑 | 2025-06-19 |
2698719 | 조건부컴파일 질문입니다.~ (2) | 큐트 | 2025-06-19 |
2698693 | 재귀 함수 에러 | 바닐라 | 2025-06-19 |
2698673 | 고민이있는데 들어좀주세요!! (1) | 초코맛캔디 | 2025-06-19 |
2698644 | 1부터 n까지의 합을 구하는데 엄청긴숫자의 합을 구할때는 어떻게 해야하나요? (4) | 슬우 | 2025-06-18 |
2698616 | 다른 함수로 안넘어갑니다..;;; | 도1도캣 | 2025-06-18 |
2698587 | 배열하다 막혀서... (3) | WhiteCat | 2025-06-18 |
2698559 | 문자열을 비우는방법 (2) | 하늘 | 2025-06-18 |
2698528 | 착하고 친절한 선생씌구해염~ㅋㅋ (4) | 옆집언니야 | 2025-06-17 |
2698502 | 자료구조 큐 | 캔서 | 2025-06-17 |
2698477 | 실행화면 배경문의요 | 선아 | 2025-06-17 |
2698430 | 변수의 값이 저장이 않되네요;; (4) | 피네 | 2025-06-16 |
2698404 | C#을 배울려고 하는데 C나 C++을 알아야 하나요 ?? (1) | 신당 | 2025-06-16 |
2698342 | 프로그램 질문점녀 (4) | 데빌의눈물 | 2025-06-16 |
2698318 | 파일 입출력 질문입니다~ (2) | 꽃 | 2025-06-15 |