- 博客(0)
- 资源 (3)
空空如也
非抢占按优先数调度算法源代码
非抢占按优先数调度算法源代码
#include <stdio.h>
#include <stdlib.h>
#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 pro1 *head,int time);
struct pro1* creatList() //创建链表,按照进程的到达时间排列
{
struct pro1* head=(struct pro1*)malloc(sizeof(struct pro1));
head->next=NULL;
struct pro1 *s;
int i;
for(i=0;i<MAX;i++)
{
s=(struct pro1*)malloc(sizeof(struct pro1));
printf("请输入进程名:\n");
scanf("%d",&(s->num));
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) //查找第一个到达时间大于等于AT的节点,返回其前一个指针
2009-11-27
经典C源程序100例
经典C源程序100例
经典C源程序100例
【程序1】
题目:有1、2、3、4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少?
1.程序分析:可填在百位、十位、个位的数字都是1、2、3、4。组成所有的排列后再去掉不满足条件的排列。
2.程序源代码:
main()
{
int i,j,k;
printf("\n");
for(i=1;i<5;i++) /*以下为三重循环*/
for(j=1;j<5;j++)
for (k=1;k<5;k++)
{
if (i!=k&&i!=j&&j!=k) /*确保i、j、k三位互不相同*/
printf("%d,%d,%d\n",i,j,k);
}
}
【程序2】
题目:企业发放的奖金根据利润提成。利润(I)低于或等于10万元时,奖金可提10%;利润高于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可可提成7.5%;20万到40万之间时,高于20万元的部分,可提成5%;40万到60万之间时高于40万元的部分,可提成3%;60万到100万之间时,高于60万元的部分,可提成1.5%,高于100万元时,超过100万元的部分按1%提成,从键盘输入当月利润I,求应发放奖金总数?
1.程序分析:请利用数轴来分界,定位。注意定义时需把奖金定义成长整型。
2.程序源代码:
main()
{
long int i;
2009-11-27
生产者——消费者 c语言
生产者——消费者 c语言
C语言
#include
#define size 5
int empty,full,in,out,a[size]={0},i,m=1;
void produce()
{
int j;
if(empty>0)
{
empty--;
a[in]=1;
printf("生产一件产品,1为继续生产,2为消费\n");
in=(in+1)%size;
scanf("%d",&j);
switch(j)
{
case 1: i=j;break;
case 2: i=j;break;
default: printf("结束操作");m=0;
}
full++;
}
else
2009-11-27
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人