麻烦高手帮忙!!!

yblue yblue 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
一下是我的代码,总是运行到最后的时候提示有问题要关闭?这是一个关于作业调度的程序。请高手指点!!!

#include<iostream>
#include"stdio.h"
#define getjcb(type)(type *)malloc(sizeof(type))
#define NULL 0


using namespace std;

int m=0, n=0;

struct JCB {
char name[10]; //作业名
float arriveTime; //作业到达时间
float startTime; //开始运行时间
float neceTime; //需要的时间
float finishTime; //完成时间
char state; //作业状态(运行(r)或等待(w))
JCB *next;
} *p, *arrStart,*q, *arrStart1;


void Sort()
{
p->next = arrStart->next;
arrStart->next = p;
}

void ReSort()
{
arrStart1 = getjcb(JCB);
arrStart1->next = NULL;
for(q=arrStart->next; q!=NULL; q=q->next)
{
p = getjcb(JCB);
for(int i=0; i<10; ++i)
{
p->name[i] = q->name[i];
}
p->arriveTime = q->arriveTime;
p->state = q->state;
p->neceTime = q->neceTime;
p->next = arrStart1->next;
arrStart1->next = p;
}
}

void Run()
{
cout<<"初始状态:"<<endl;
p = arrStart1->next;
while(p != NULL)
{
cout<<"作业"<<"\t"<<"到达时间"<<"\t"<<"所需时间"<<endl;
cout<<p->name<<"\t"<<p->arriveTime<<"\t\t"<<p->neceTime<<endl;
p = p->next;
}
cout<<endl<<"开始运行:"<<endl<<endl;
p = arrStart1->next;
p->state = 'r';
while(p != NULL)
{
int t = p->neceTime;
while(t >0)
{
t--;
cout<<"作业"<<"\t"<<"到达时间"<<"\t"<<"所需时间"<<"\t"<<"还需时间"<<endl;
cout<<p->name<<"\t"<<p->arriveTime<<"\t\t"<<p->neceTime<<"\t\t"<<t<<endl;
}
cout<<"作业"<<p->name<<"完成"<<endl;
cout<<endl;
q = p;
p = p->next;
p->state = 'r';
arrStart1->next = p;
free(q);
}
}

void main()
{
int k = 1;
arrStart = getjcb(JCB);
arrStart->next = NULL;
cout<<"请输入作业的数目: ";
cin>>n;
cout<<endl;
for(int j=0; j<n; ++j, ++k)
{
cout<<"作业"<<k<<"的名称: ";
p = getjcb(JCB);
cin>>p->name;
cout<<"所需时间: ";
cin>>p->neceTime;
p->arriveTime = k;
p->state = 'w';
Sort();
cout<<endl;
}
ReSort();
Run();
}
...全文

相关推荐

评论 4
收藏 已收藏
分享
返回顶部
yblue
C++ 语言 65,214 成员 250,514 内容