I am creating an SJF code ( no preemtion). It is functioning correctly (as far as i can tell) but always some processes(1-4 out of 10) are not sorted correctly. Assume there are 10 processes
I attached my code with comments. Also here is my logic behind it.
Burst times and arrival times are generated and are known before the algoithm begins
1) I sort all processes and find the one that is going to be executed first ( if two have same arrival time its the one with the lower burst time)
2)After this there are three variables. Completed ( how many processes are done), Totaltime( time that has passed) and counter ( how many processes have arrived after 1 was completed
3) i begin a repetition for i=1 until 10 ( the rest 9 processes). Totaltime has been initialized as burst+arrival. each time count how many processes have arrived. Also perform a completed++ at the very end of the repetition (after the next steps that is)
4) the tricky part : perform bubblesort for 1=completed until counter-1 and for j=i until counter ( the problem almost certainly is here)
5)The next process has been found , so its burst time is added to totaltime, counter is set to 0 and some other calculations which you have to check
turnaroundtime ( time that passed from the arrival of a process until its completation) and waittime ( time passed from arrival until it was started)
P.S 1)If you think my logic is totally flawed you are free to make your own version but all the variables mentioned have to be there
7 freelancers are bidding on average €51 for this job
Can help... I am an Expert... Please check the past projects I have handled and check my reviews for what employers have to say about my work... Can start right now...