SJF算法,到达时间不正常

时间:2018-01-02 12:24:07

标签: c algorithm operating-system

add_filter( 'post_type_link', 'change_product_request', 10, 3 );

function change_product_request( $post_link, $post, $leavename ) {

        if ( 'product' != $post->post_type || 'publish' != $post->post_status ) {
            return $post_link;
        }

        $post_link = str_replace( "/{$post->post_type}/" , '/', $post_link );

        return $post_link;
}

我想大多数人都知道这个算法(SJF)应该做什么,我被告知编码一个,这就是我得到的。 我决定使用包含时间和id的结构“进程”。

我认为到达时间的排序工作得很好但有时候,在printf上,我得到相同字母(过程)的2倍,我得到的Timearound和等待时间不对,我不是真的我知道如何解决这个问题,因为我认为我使用的公式是正确的。任何帮助都会很好。

无论在哪里,“rafaga”都意味着“爆发时间”

1 个答案:

答案 0 :(得分:0)

SJF 算法中,首先根据到达时间进行排序 跟随,然后根据突发时间进行排序< / em>的

现在查看您的排序代码,似乎您使用的是selection sort,而且您的代码不正确。内部循环总是从一个索引开始,而不是外部索引j = i + 1,而不是j = 0正确的排序是:

for (i = 0;i < n;i++){

    for(j = i+1;j < n;j++)
    {
     if(p[i].tL < p[j].tL){

     aux=p[j];
     p[j]=p[i];
     p[i]=aux;
     }

    }
}

您对burst time的排序看起来也不正确。照顾好这些小事,你的代码就是正确的。从侧面说明一旦理解了基础知识, SJF 就是最简单的代码。