nextfit

 package nxtftpr;


import java.util.*;


public class NXT_PR {

public static void NextFit(int blockSize[], int m, int processSize[],int n) {

int allocated []= new int[n];

for (int i=0;i<n;i++) {

allocated[i]=-1;

}

int j=0, t=m-1;

for(int i=0;i<n;i++) {

while(j<m) {

if(blockSize[j]>=processSize[i]) {

allocated[i]=j+1;

blockSize[j]-=processSize[i];

t=(j-1)%m;

break;

}

if(j==t) {

t=(j-1)%m;

break;

}

j=(j+1)%m;

}

}

        System.out.print("\nProcess No.\tProcess Size\tBlock no.\n");

        for (int i = 0; i < n; i++) {

            System.out.print( i + 1 + "\t\t" + processSize[i]

                    + "\t\t");

            if (allocated[i] != -1) {

                System.out.print(allocated[i]);

            } else {

                System.out.print("Not Allocated");

            }

            System.out.println("");

        }

}


public static void main(String[] args) {

int blockSize[] = {100,500,200,300,600}; //{100,200,300,500,600};

        int processSize[] = {212,417,112,426}; //{112,212,417,426};

        int m = blockSize.length;

        int n = processSize.length;

        NextFit(blockSize, m, processSize, n);

}


}


Comments

Popular Posts