View Full Version : Algorithm for First Fit and best Fit
flint0131
12-11-2009, 04:22 AM
Can someone help me with the algorithm of First fit and Best fit?
Using only two parameters
public void FirstFit( int taskSize, String taskName )
public void BestFit( int taskSize, String taskName )
I'm almost finish, I'm having a hard time on the algorithm.
TheShaner
12-11-2009, 05:32 PM
We don't do your homework, you're not showing any work you've done, and you haven't told us exactly what's wrong, i.e. compilation errors, algorithm not producing correct results, etc. We give help, not code.
Visual Representation of Best Fit Algorithm - http://www.youtube.com/watch?v=QSXB693Hrls
First Fit is pretty self-explanatory. The process will be allocated to the first memory location that can hold it.
For both, you're going to iterate over your memory list. For Best Fit, you must search the entire list, while First Fit will stop once it reaches a memory location that can hold it. In Best Fit, you'll have a variable that will update as you search, storing the best location that fits the process the best.
-Shane
flint0131
12-11-2009, 05:47 PM
If I don't have codes, will ask for a function?
I tried it, but it's so noobish.. That's why I need to see the code, then I will analyze it..
Anyway, for shame sake..
Her's my code :
class Allocate {
public void FirstFit( int JobSize, String JobName ) {
MemoryAlloc baby = new MemoryAlloc();
String names = "";
MemBlock mem = new MemBlock();
for ( int x = 1; x <= mem.blocks.length; x++ ) {
if ( mem.blocks[x] <= JobSize ) {
mem.blocks[x] = JobSize;
names = baby.appStatus[1];
if ( names == baby.appStatus[0] ) {
break;
}
}
}
}
public void BestFit ( int JobSize, String JobName ) {
// methods!!!
// algorithM!!!
}
}
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.