Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

# Thread: Algorithm for First Fit and best Fit

1. ## Algorithm for First Fit and best Fit

Can someone help me with the algorithm of First fit and Best fit?

Using only two parameters

I'm almost finish, I'm having a hard time on the algorithm.

• 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

• 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 :
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!!!
}
}```

•

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•