资源简介
C语言电梯调度算法,数据结构课程设计
代码片段和文件信息
#include
#include
#define GoingUp 1
#define GoingDown 2
#define SpeedUp 3
#define SpeedDown 4
#define SlowUp 5
#define SlowDown 6
#define Idle 7
#define Stop 8
#define DoorOpen 9
#define DoorOpening 10
#define DoorCloseing 11
#define CloseTest 40
#define OverTime 300
#define Accelerate 15
#define UpTime 51
#define DownTime 61
#define UpDecelerate 14
#define DownDecelerate 23
#define DoorTime 20
#define InOutTime 25
#define MaxTime 10000
#define MaxFloor 5
#define baseFloor 1
typedef struct Person{
int Id;
int OutFloor;
int GiveupTime;
struct Person* next;
}Person;
typedef struct Activity{
int time;
void(*fn)(void);
struct Activity* next;
}Activity;
typedef struct Person_Ele{
int Id;
struct Person_Ele* next;
}Person_Ele;
int AddQueue(int floorstruct Person* p);
void AddAct(int timevoid(*fn)(void));
void TestPeople();
void DoTime();
void Input(void);
void testinout(void);
void doclosedoor(void);
void doopendoor(void);
void doout(void);
void doin(void);
void doup(void);
void dodown(void);
void domove(void);
void doslow(void);
void tofirst();
int GetWhere(void);
int Time=0;
int CallUp[MaxFloor]={0};
int CallDown[MaxFloor]={0};
int CallCar[MaxFloor]={0};
int Floor=baseFloor;
int State=Idle;
int PersonId=0;
Activity activity={0NULLNULL};
Person_Ele Stack[5]={0};
Person Queue[5]={0};
int main(){
int i;
for(i=0;i Stack[i].next=NULL;
Queue[i].next=NULL;
}
activity.next=NULL;
Input();
DoTime();
return 0;
}
int AddQueue(int floorPerson* p){
Person* tmp=&Queue[floor];
while(tmp->next!=NULL){
tmp=tmp->next;
}
tmp->next=p;
return 0;
}
void AddAct(int timevoid(*fn)(void)){
time=Time+time;
struct Activity* act;
act=(struct Activity*)malloc(sizeof(struct Activity));
act->next=NULL;
act->fn=fn;
act->time=time;
struct Activity* p=&activity;
while(p->next!=NULL){
if(p->next->time>time)
break;
p=p->next;
}
act->next=p->next;
p->next=act;
}
void TestPeople(){//这是检测每层队列是否有人放弃,有人放弃就将他踢出队列
int i;//这个函数每个时间都会被调用,效率相对较低
for(i=0;i Person* p=Queue[i].next;
Person* q=&Queue[i];
if(p==NULL)
continue;
while(p!=NULL){
if(p->GiveupTime<=Time){
if(Floor==i&&(State>=Idle))
break;
q->next=p->next;
printf(“用户%d放弃了等待!\n“p->Id);
free(p);
p=q->next;
continue;
}
q=p;
p=p->next;
}
}
}
void Input(void){//输入人员信息,这个需要手动调用一次,之后就根据定时器调用了
Person* p = (Person*)malloc(sizeof(Person));
int inflooroutfloorgiveuptimeintertime;
while(1){
printf(“请输入用户的起始楼层:“);
scanf(“%d“&infloor);
printf(“请输入用户的目标的楼层:“);
scanf(“%d“&outfloor);
printf(“请输入用户的最长容忍时间:“);
scanf(“%d“&giveuptime);
printf(“请输入下一个用户的到来时间:“);
scanf(“%d“&intertime);
if(!(infloor<0||infloor>MaxFloor-1||outfloor<0||outfloor>MaxFloor-1)&&(infloor!=outfloor))
break;
printf(“错误的用户信息录入
相关资源
- 操作系统c语言模拟文件管理系统844
- C语言开发实战宝典
- C++中头文件与源文件的作用详解
- C语言代码高亮html输出工具
- 猜数字游戏 c语言代码
- C语言课程设计
- 数字电位器C语言程序
- CCS FFT c语言算法
- 使用C语言编写的病房管理系统
- 通信过程中的RS编译码程序(c语言)
- 计算机二级C语言上机填空,改错,编
- 用回溯法解决八皇后问题C语言实现
- 简易教务管理系统c语言开发文档
- 操作系统课设 读写者问题 c语言实现
- 小波变换算法 c语言版
- C流程图生成器,用C语言代码 生成C语
- 3des加密算法C语言实现
- 简单的C语言点对点聊天程序
- 单片机c语言源程序(51定时器 八个按
- 个人日常财务管理系统(C语言)
- c语言电子商务系统
- 小甲鱼C语言课件 源代码
- 将图片转换为C语言数组的程序
- C语言实现的一个内存泄漏检测程序
- DES加密算法C语言实现
- LINUX下命令行界面的C语言细胞游戏
- 用单片机控制蜂鸣器播放旋律程序(
- 学校超市选址问题(数据结构C语言版
- 电子时钟 有C语言程序,PROTEUS仿真图
- 尚观培训linux许巍老师关于c语言的课
评论
共有 条评论