短作业优先算法(非剥夺)
代码是用C加加写的
需要先建立一个Win32 Console Application工程,在其中建一个C++的文件
使用的是冒泡法对到达时间进行从小到大排序
源代码
#include “stdio.h”
#define N 20
int ct;//当前时间
struct process
{
int no;//序号
int arrtime;//到达时间
int runtime;//运行时间
int starttime;//开始时间
int endtime;//结束时间
int roundtime;//周转时间
int flag;//标志位 初值为 运行结束为1,2,3
};
void bubblesort(process a[],int n)//对到达时间进行从小到大排序
{
int i,k;
process t;
for(i=0;i<n-1;i++)
for(k=0;k<n-1-i;k++)
{
if(a[k].arrtime>a[k+1].arrtime)
{
t=a[k];
a[k]=a[k+1];
a[k+1]=t;
}
}ct=a[0].arrtime;
}
void bubblesort2(process a[],int n)//对执行顺序进行从小到大排序号
{
int i,k;
process t;
for(i=0;i<n-1;i+