Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    May 2009
    Posts
    59
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Algorithm for First Fit and best Fit

    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.

  • #2
    Senior Coder TheShaner's Avatar
    Join Date
    Sep 2005
    Location
    Orlando, FL
    Posts
    1,126
    Thanks
    2
    Thanked 40 Times in 40 Posts
    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

  • #3
    New Coder
    Join Date
    May 2009
    Posts
    59
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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
    •