import java.util.*;
class Partition
{
private int partstart;
private int partend;
private int partsize;
private int prosssize;
private int pid;
//private int intfrag;
private boolean empty;
private Partition next;
Partition Head=null;
public void createDynamicPartitions(int totmem)
{
Partition p=new Partition();
p.partsize=totmem;
//p.prosssize=0;
p.pid=-1;
//p.intfrag=0;
p.empty=true;
p.next=null;
p.partstart=0;
p.partend=totmem-1;
Head=p;
memStatus();
}
private Partition selectFirstHole(int prsize)
{
Partition temp=Head,first=null;
while(temp != null)
{
if (temp.empty && temp.partsize >= prsize)
{
break;
}
temp=temp.next;
}
return first;
}
public void loadProcess(int pid,int prsize)
{
Partition hole=selectFirstHole(prsize);
if(hole null)
System.out.println("There is no Process with ID :"+dpid);
else
memStatus();
}
private void memStatus()
{
Partition temp=Head;
System.out.println("Current Memory Status");
// int totfrag=0;
while(temp != null)
{
if(temp.empty)
System.out.println(temp.partstart+"-"+temp.partend+" : is hole of size "+temp.partsize);
else
System.out.println(temp.partstart+"-"+temp.partend+" :Memory with Process ID "+temp.pid+" of size "+temp.partsize);
//totfrag=totfrag+temp.intfrag;
temp=temp.next;
}
//System.out.println("\n Total Internal Fragmentation : "+totfrag);
}
}
public class FirstFit
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter Total Memory size :");
int totmem=sc.nextInt();
//System.out.println("Enter number of partitions :");
//int numofpartions=sc.nextInt();
//creating partitions
Partition dp=new Partition();
dp.createDynamicPartitions(totmem);
while(true)
{
System.out.println("Menu");
System.out.println("1.Load Process");
System.out.println("2.Remove Process");
System.out.println("3.Exit");
System.out.println("Enter ur Choice : ");
int ch=sc.nextInt();
switch(ch)
{
case 1:
System.out.println("Enetr Process ID : ");
int pid=sc.nextInt();
System.out.println("Enetr Process size : ");
int prsize=sc.nextInt();
dp.loadProcess(pid,prsize);
break;
case 2:
System.out.println("Enetr Process ID : ");
int dpid=sc.nextInt();
dp.removeProcess(dpid);
break;
case 3:
System.exit(0);
//break;
default:
System.out.println("*** Wrong Choice ***\n Choice must be in b/w 1- 3");
}
}
}
}
Chat with our AI personalities
yes we can do it,in c
In Java programming language, an algorithm refers to a sequence of instructions that have been specified to undertake a particular task within a certain time. An algorithm can take no or several inputs but will generate at least one output.
#include
You can get the Java source code for the BIDE data mining algorithm here : (link moved to link section) It is an open-source data mining framework that includes the BIDE algorithm
Java byte code.