本项目提供了一种基于非抢占式的优先级调度算法的实现源代码。此算法在任务处理时依照优先权分配处理器资源,适用于多种操作系统环境下的进程或线程管理。
非抢占式优先数调度算法源代码
```c
#include
#include
#define MAX 5 // 进程数量
// 结构体定义进程节点
struct pro1 {
int num; // 进程名
int arriveTime; // 到达时间
int burst; // 执行时间
int weight; // 权重(优先数)
struct pro1 *next;
};
// 函数声明
struct pro1* creatList();
void insert(struct pro1 *head, struct pro1 *s);
struct pro1* searchByAT(struct pro1 *head, int AT);
void run(struct pro1 *head);
void del(struct pro1* p);
int getCount(struct propro1 *head, int time);
// 创建链表,按照进程的到达时间排列
struct pro1* creatList() {
struct pro1* head = (struct pro1*)malloc(sizeof(struct pro1));
head->next = NULL;
for(int i=0; inum));
printf(请输入到达时间:\n);
scanf(%d, &(s->arriveTime));
printf(请输入执行时间:\n);
scanf(%d, &(s->burst));
printf(请输入优先数(权重):\n);
scanf(%d, &(s->weight));
s->next = NULL;
insert(head, s);
}
return head;
}
// 插入节点
void insert(struct pro1 *head, struct pro1 *s) {
struct pro1 *p = searchByAT(head, s->arriveTime);
s->next = p->next;
p->next = s;
return;
}
// 查找第一个到达时间大于等于给定值的节点,返回其前一个指针
struct pro1* searchByAT(struct pro1 *head, int AT) {
}
```