#include#include#include#include#includeusing namespace std;
#define maxn 100
int time=0; //定義時間,為全域性變數,第乙個程序到達時為0;
typedef structproducer; //程序結構體
float rep(producer s,int time) //計算優先權函式
int n; //n為全域性變數,表示程序的總數量
producer p[maxn]; // 定義程序佇列陣列
void initp(producer p) //程序陣列的初始化
cout<<"請輸入需要加入的程序數量:"<>n;
// fscanf(fp,"%d",&n);
int i;
for(i=0;i>p[i].arrivetime;
cout<<"請輸入程序名: ";
cin>>p[i].name;
cin>>p[i].servetime;
}// fclose(fp);
}int compare(producer p1,producer p2)
} } time+=p[0].servetime; //程序完成後的時刻
cout<<"第乙個執行程序: "
fprintf(fp,"第乙個執行程序: %s\n",p[0].name);
cout<<"程序完成後的時刻為:"
int k=0,count=n-1; //count表示剩餘程序;
while(count--)
for(i=k;i}
}time+=p[k].servetime;
cout<<"第"
fprintf(fp,"第%d個執行:%s\n程序完成後的時刻為:%d\n",k+1,p[k].name,time);
} fclose(fp);
return 0;
}
動態優先權程序排程演算法
include include define ready 1 define block 2 struct pcb pcb ready queue head null pcb block queue head null 建立了就緒佇列和阻塞佇列,均包含頭結點,以後的節點插入均採取插入排序 void i...
程序排程 高優先權優先
include stdio.h include include define getpch type type malloc sizeof type define null 0 struct pcb ready null,p ready p 為全域性變數 typedef struct pcb pcb...
排程演算法FCFS SJF和優先權排程的介紹和例題
一 先來先服務fcfs first come first serve 1.思想 選擇最先進入後備 就緒佇列的作業 程序,入主存 分配cpu 2.優缺點 優點 對所有作業 程序公平,演算法簡單穩定 缺點 不夠靈活,對緊急程序的優先處理許可權不夠,在相同時限下處理任務數量可能更少 二 短作業優先sjf ...