I was writing a SSTF disk scheduling algorithm code in SCILAB and during running after displaying first 3 values (41,34,11) correctly its always showing head at -1. Can somebody tell whats the problem in code? I tried to give a different if condition too but it wasn't also giving correct output.
clear
clf;
seek = 0
x = 8
l = list(176,60,79,92,114,11,34,41)
head = 50
mi = 1
for j = 1:x
for i=1:x
if (l(i)~=(-1))then
if( abs(head - l(i)) < abs(head -l(mi))) then
mi = i
end
end
end
seek = seek + abs(head - l(mi))
head = l(mi)
h(j) = head
se(j) = seek
mprintf('Head is at %i and seek is %i\n',head,seek)
l(mi) = -1
end
plot(h,se)
scatter(h,se)
