Borrar filtros
Borrar filtros

FCFS code

11 visualizaciones (últimos 30 días)
Ayda
Ayda el 7 de Abr. de 2012
Respondida: Sanjana el 5 de Mzo. de 2024
Good Morning\ Evening
I have number of processes and each process has its arrival time the question require to simulate processes using First Come First Serve.
I wrote this code for FCFS but did not return a correct values the result should display the order of FCFS
numOfJobs=input('Enter the number of jobs to run = ');
for i=1:numOfJobs
job(i)=i;
end
job1=job;
arrivalTime=input('Enter the arrival time of each job = ,[in vector form] ');
for i=1:numOfJobs-1
y=i+1;
for j=y:numOfJobs
if(arrivalTime(j)<arrivalTime(i))
firstcome=job(j);
job(j)=job(i);
job(i)=firstcome;
end
end
end
job;
out2=[out1 arrivalTime']
Also I have to figure out the starting time, the completion time and total waiting Time for each process

Respuestas (2)

Walter Roberson
Walter Roberson el 7 de Abr. de 2012
You can replace most of what you have written with
[sortedArrivalTimes, job] = sort(arrivalTime);
It is not possible to work out the starting and completion and waiting times without knowing how long each job takes. Other than that you can say that the starting time for the first job to arrive will be sortedArrivalTimes(1)
  2 comentarios
Ayda
Ayda el 7 de Abr. de 2012
thank you very much
but if I want to use the for loop,, where is the mistake
Walter Roberson
Walter Roberson el 7 de Abr. de 2012
Using bubble sort is a mistake more often than not...

Iniciar sesión para comentar.


Sanjana
Sanjana el 5 de Mzo. de 2024
numOfJobs=input('Enter the number of jobs to run = ');
for i=1:numOfJobs
job(i)=i;
end
job1=job;
arrivalTime=input('Enter the arrival time of each job = ,[in vector form] ');
for i=1:numOfJobs-1
y=i+1;
for j=y:numOfJobs
if(arrivalTime(j)<arrivalTime(i))
firstcome=job(j);
job(j)=job(i);
job(i)=firstcome;
end
end
end
job;
out2=[out1 arrivalTime']

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by