#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "time.h"
typedef struct node /*创建PCB*/
{
char name; /*进程名*/
int createtime; /*进程创建时间*/
int needtime; /*进程完成所需时间*/
struct node *next; /*链指针*/
}PCB;
PCB* createpro()
{
PCB* runpro;
PCB* newpcb;
PCB* currentpcb;
int i;
srand((unsigned)time(NULL));
runpro=(PCB*)malloc(sizeof(PCB));
runpro->name = 'A';
runpro->createtime = rand() % 100;
runpro->needtime = rand() % 100;
runpro->next = NULL;
currentpcb = runpro;
for(i=1;i<=4;i++)
{
newpcb=(PCB*)malloc(sizeof(PCB));
newpcb->name = 'A'+i;
newpcb->createtime = rand() % 100;
newpcb->needtime = rand() % 100;
newpcb->next = NULL;
currentpcb->next = newpcb;
currentpcb = newpcb;
}
return runpro;
}
void fcfs( PCB* run)
{
PCB* ok;
PCB* current;
char t1;
int t2;
int t3;
ok = NULL;
while( ok != run )
{
current = run;
while( current->next != ok)
{ if( current->createtime > current->next->createtime )
{
t1 = current->name;
t2 = current->createtime;
t3 = current->needtime;
current->name = current->next->name;
current->createtime = current->next->createtime;
current->needtime = current->next->needtime;
current->next->name = t1;
current->next->createtime = t2;
current->next->needtime = t3;
}
current = current->next;
}
ok = current;
}
}
void runpro( PCB* run)
{ PCB* currentpcb;
clrscr();
printf(" DISPLAY OF THE PROGRESS:\n");
printf("************************************************\n");
currentpcb = run;
while( currentpcb != NULL)
{
printf("pro name:%c", currentpcb->name);
printf(" pro create time:%d", currentpcb->createtime);
printf(" pro need time:%d\n", currentpcb->needtime);
currentpcb = currentpcb->next;
}
printf("************************************************\n");
}
void delpcb(PCB* run)
{
PCB* cur;
while( run != NULL)
{
cur = run;
run = run->next;
free(cur);
}
}
void main()
{
PCB* run;
run = createpro();
fcfs(run);
runpro(run);
delpcb(run);
}
FCFS.rar_fcfs _site:www.pudn.com_进程调度 FCFS
版权申诉
45 浏览量
2022-09-24
13:06:10
上传
评论 1
收藏 874B RAR 举报
weixin_42653672
- 粉丝: 93
- 资源: 1万+
最新资源
- 机械设计整经机上纱自动化sw20非常好的设计图纸100%好用.zip
- Screenshot_20240427_031602.jpg
- 网页PDF_2024年04月26日 23-46-14_QQ浏览器网页保存_QQ浏览器转格式(6).docx
- 直接插入排序,冒泡排序,直接选择排序.zip
- 在排序2的基础上,再次对快排进行优化,其次增加快排非递归,归并排序,归并排序非递归版.zip
- 实现了7种排序算法.三种复杂度排序.三种nlogn复杂度排序(堆排序,归并排序,快速排序)一种线性复杂度的排序.zip
- 冒泡排序 直接选择排序 直接插入排序 随机快速排序 归并排序 堆排序.zip
- 课设-内部排序算法比较 包括冒泡排序、直接插入排序、简单选择排序、快速排序、希尔排序、归并排序和堆排序.zip
- Python排序算法.zip
- C语言实现直接插入排序、希尔排序、选择排序、冒泡排序、堆排序、快速排序、归并排序、计数排序,并带图详解.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
评论0