BestFit算法实现。仅显示第一个输出

时间:2019-03-15 15:18:51

标签: c memory-management best-fit

我正在尝试在C中实现最佳拟合算法。问题是我的实现只打印了chunksizeArray的第一个条目以及processSizeArray的所有值。我似乎找不到我要去哪里。请帮助我。

这是代码

#include<stdio.h>
#include<conio.h>
#define MAX 20
int temp[MAX] , chunkSize[MAX] , chunkSizeCopy[MAX] , i , j , c , size , 
minimum , location , n , processes , blocks , processSize[MAX] , pos; 

int a_size(int ar[]) 
{
    return(sizeof(ar)/sizeof(ar[0]));
}
int min(int temp[] , int n)
{

for(i = 0 ; i <= n ; i++)
    if(temp[i] >= 0)
    {
        minimum = temp[i];
        break;
    }

for (c = 0; c < size; c++)
{
    if (temp[c] < minimum && temp[c] >= 0)
    {
       minimum = temp[c];
       //location = c+1;
    }
}

return c;
}

void bestFit()
{

    //printf("Size  = %d",n);
    for(i = 0 ; i <= processes ; i++){
    for(j = 0 ; j <= blocks ; j++)
    {
        temp[i] = chunkSizeCopy[i] - processSize[i];
        //n = a_size(temp);
    }
}
printf("Chunk Size\t Process Size\n");
for(i = 0;i<processes;i++){
    for(j = 0;j<blocks;j++)
{
        pos = min(temp , blocks);
        chunkSizeCopy[pos] = 9999;
        printf("%d\t\t%d" , chunkSize[pos],processSize[j]);
        printf("\n");
}
}
}




/*for(i = 0 ; i <= n ; i++)
{
    if(temp[i] >= 0)
    {
        pos = min(temp , n);
        chunkSizeCopy[pos] = 99999;
    }
}*/


/*i = 0 ;
n = sizeof(temp);
bubbleSort(temp , n);

while(temp[i] >= 0)
{
    result[i]= temp[i];
    i++;
}*/




 int main()
 {
printf("Enter the number of processes\n");
scanf("%d" , &processes);

printf("Enter the number of blocks\n");
scanf("%d" , &blocks);

printf("Enter the chunk size\n");
for(i = 0 ; i < blocks;i++)
{
    scanf("%d" , &chunkSize[i]);
    chunkSizeCopy[i] = chunkSize[i];
}   


printf("Enter the process size\n");
for(i = 0 ; i < processes;i++)
    scanf("%d" , &processSize[i]);

bestFit();      
}

这是上面代码的测试运行

Enter the number of processes
3
Enter the number of blocks
3
Enter the chunk size
212
417
112
Enter the process size
300
500
200
Chunk Size       Process Size
212             300
212             500
212             200

0 个答案:

没有答案