Filter löschen
Filter löschen

FCFS code

11 Ansichten (letzte 30 Tage)
Ayda
Ayda am 7 Apr. 2012
Beantwortet: Sanjana am 5 Mär. 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

Antworten (2)

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

Melden Sie sich an, um zu kommentieren.


Sanjana
Sanjana am 5 Mär. 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']

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by