%Queue sorting by priority
function Sorting;

global Queue MatrixIn
global ValueCount

for i=1:length(Queue)
     if Queue(i) == 0
        point = i-1;
        break;
     end;
end;

for j=1:(point-2)
for i=1:(point-1)
    if MatrixIn(4,Queue(i))>MatrixIn(4,Queue(i+1))
        buf = Queue(i);
        Queue(i) = Queue(i+1);
        Queue(i+1) = buf;
    end;
end;
end;