首页 > 解决方案 > 在最短进程下一个算法中获得分段错误-核心转储错误

问题描述

#include<stdio.h>
#include <limits.h>
#include <stdbool.h>

int main(int argc,char* argv[])
{
    int n=4;
    int bt[4];
    bt[0]=6;
    bt[1]=8;
    bt[2]=7;
    bt[3]=3;
    int at[4];
    at[0]=1;
    at[1]=1;
    at[2]=2;
    at[3]=3;
    int shortest=INT_MIN;
    int minm= INT_MAX;
    int t=0;
    bool check= false;
    int complete=0;
    while(complete!=n)
    {
        for(int i=0; i<4; i++)
        {
            if(bt[i] > 0 && bt[i] < minm  && at[i] <= t)
            {
                shortest=i;
                minm= bt[i];
                check=true;
            }
        }
        if(check=false)
        {
            t++;
            continue;
        }

        bt[shortest]--;
        minm= bt[shortest];

        if(minm=0)
        {
            minm=INT_MAX;
        }


        if(bt[shortest]=0)
        {
            complete++;
            check=false;
        }
        t++;
    }


    return 0;
}

这是最短过程下一个算法的代码。我尝试在 c# 中运行这个程序,它运行良好,但是当我在 linux 中使用 c 语法实现这个算法时,它给了我一个分段错误 - 核心转储错误。有人可以帮忙解决这个问题吗?

标签: c

解决方案


推荐阅读