Azzera filtri
Azzera filtri

FCFS code

11 visualizzazioni (ultimi 30 giorni)
Ayda
Ayda il 7 Apr 2012
Risposto: Sanjana il 5 Mar 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

Risposte (2)

Walter Roberson
Walter Roberson il 7 Apr 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 Commenti
Ayda
Ayda il 7 Apr 2012
thank you very much
but if I want to use the for loop,, where is the mistake
Walter Roberson
Walter Roberson il 7 Apr 2012
Using bubble sort is a mistake more often than not...

Accedi per commentare.


Sanjana
Sanjana il 5 Mar 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']

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by