Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write function sjf to do the following a . Return type void b . Parameter list i . An array for the process IDs, data
Write function sjf to do the following
a Return type void
b Parameter list
i An array for the process IDs, data type int ie process
ii An array for the arrival times, data type int ie at
iii. An array for the burst times, data type int ie bt
c Declare an array for the wait times, data type int ie wt
d Declare an array for the turnaround times, data type int ie tat
e Declare a variable for the current index for sorting ie idx
f Declare a variable for temporary storage for sorting ie temp
g Write a nested loop to sort the process data based on burst time
a Outer loop iterates for the number of processes ie PID
i Set variable idx to the current value of the outer
loop control variable
ii Inner loop iterates for the number of processes ie
PID with the loop control variable initialized to the
outer loop control variable plus
If the value in array bt index of the inner
loop control variable, is less than the value
in array bt index of variable idx
a Set variable idx to the current value
of the inner loop control variable
iii. Swap the burst times
Set variable temp equal to array bt index
of the outer loop control variable
Set the value of array bt index of the outer
loop control variable, equal to array bt
index of variable idx
Set the value of array bt index of variable
idx, equal to variable temp
iv Swap the process IDs
Set variable temp equal to array process,
index of the outer loop control variable
Set the value of array process, index of the
outer loop control variable, equal to array
process, index of variable idx
Set the value of array process, index of
variable idx, equal to variable temp
v Swap the arrival times
Set variable temp equal to array at index
of the outer loop control variable
Set the value of array at index of the outer
loop control variable, equal to array at
index of variable idx
Set the value of array at index of variable
idx, equal to variable temp
h Initialize index in array wt to
i Calculate the wait times for each process
i Iterate for the number of processes ie PID starting at
index
Set the wait time in array wt at the current index
equal to the sum of burst time ie bt of the
previous index and wait time ie wt of the
previous index
j Calculate the turnaround times for each process
i Iterate for the number of processes ie PID
Set the turnaround time in array tat at the current
index equal to the sum of burst time ie bt of the
current index and wait time ie wt of the current
index
k Call function displaySchedule passing arguments
i Array process
ii Array at
iii. Array bt
iv Array wt
v Array tat
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started