资源简介
完整的六层电梯程序,已经试验过,可用,希望对各位有用,有什么建议,欢迎提出
代码片段和文件信息
#include
#include
#include
#include “lift.h“
/* some global stats */
int total_waiting = 0;
int no_of_waits = 0;
int max_wait = 0;
int min_wait = 10000000;
/*
* Initialize the floors
*/
void init_floors(struct floor_s* floors)
{
int i = 0;
for(i = 0; i < NO_OF_FLOORS; i++) {
floors[i].floor_number = i;
floors[i].num_waiting = 0;
floors[i].num_not_waiting = 0;
}
}
/*
* arrive_on_floor is called when a person arrives at a new floor.
*/
void arrive_on_floor(int time struct floor_s* floor struct person_s* person)
{
person->target_floor = -1; /* just arrived don‘t want to go
anywhere yet */
person->floor = floor->floor_number;
/* store them in the first free slot in the array */
floor->people_not_waiting[floor->num_not_waiting] = person;
floor->num_not_waiting++;
if (person->start_waiting != -1) {
total_waiting += time - person->start_waiting;
printf(“Their journey time was %d\n“ time - person->start_waiting);
if (time - person->start_waiting > max_wait) {
max_wait = time - person->start_waiting;
}
if (time - person->start_waiting < min_wait) {
min_wait = time - person->start_waiting;
}
no_of_waits++;
person->start_waiting = -1;
}
}
/*
* init_people initialized the people to start from the ground floor
*/
void init_people(struct floor_s* floors struct person_s* people)
{
int i = 0;
for(i = 0; i < NO_OF_PEOPLE; i++) {
people[i].name[0] = ‘A‘ + i;
people[i].name[1] = ‘\0‘;
people[i].start_waiting = -1;
arrive_on_floor(0 &floors[0] &people[i]);
}
}
/*
* init_lists initializes the lifts to start from the ground floor
*/
void init_lifts(struct lift_s* lifts)
{
int i;
for (i = 0; i < NO_OF_LIFTS; i++) {
lifts[i].lift_id = i;
lifts[i].occupants = 0;
lifts[i].position = 0;
lifts[i].speed = 0;
lifts[i].last_floor = 0;
lifts[i].mode = MODE_IDLE;
}
}
/*
* queue_for_list is called to add a person who was not previously
* queuing for a lift to the lift queue on their current floor
*/
void queue_for_lift(struct person_s* person struct floor_s* floor)
{
int i j = -1;
/* find the person and remoove them from the pool of people not
queuing */
for (i = 0; i < floor->num_not_waiting; i++) {
if (floor->people_not_waiting[i] == person) {
for (j = i; j < floor->num_not_waiting-1; j++) {
floor->people_not_waiting[j] = floor->people_not_waiting[j+1];
}
break;
}
}
assert(j != -1);
floor->num_not_waiting--;
floor->people_not_waiting[floor->num_not_waiting] = NULL;
/* add them to the queue of people waiting for the lift */
floor->people_waiting[floor->num_waiting] = person;
floor->num_waiting++;
}
/*
* decide_action is called to allow a person to randomly decide if
* they want to go to an
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 33792 2009-03-19 11:15 LIFT\Debug\vc60.idb
文件 28672 2009-03-19 11:15 LIFT\Debug\vc60.pdb
文件 4260 2009-03-19 11:15 LIFT\LIFT.dsp
文件 533 2009-03-19 11:15 LIFT\LIFT.dsw
文件 33792 2009-03-19 11:15 LIFT\LIFT.ncb
文件 48640 2009-03-19 11:15 LIFT\LIFT.opt
文件 771 2009-03-19 11:15 LIFT\LIFT.plg
文件 14893 2009-03-19 11:15 LIFT\main.cpp
目录 0 2009-03-19 11:15 LIFT\Debug
目录 0 2009-03-19 11:15 LIFT
----------- --------- ---------- ----- ----
165353 10
相关资源
- OpenGL绘制图形包含20多个基本
- WM算法C
- 实现进程调度算法---动态优先级
- QT_A+_记事本
- Qt 控件 实现 QComboBox输入自动提示功能
- 事件驱动 银行模拟系统
- OPENGL 字母模型
- question 6-student score management system.rar
- 八路抢答器代码
- 链表实现学生管理
- 数据结构实验-链式存储和顺序存储实
- 基于qt开发的会员管理系统
- 数据结构插队问题代码
- 输入10个整数,将其中最小的数与第一
- 科学计算导论实验报告
- 球体背面消隐课程设计及报告
- G.729的实现代码
- 东方电子DF9300通讯管理机包含规约:
- opencv检查图片中是否有人
- glaux系列包
- 无向连通图最小生成树
- 设计一个模拟计算器的程序,要求能
- 三次样条函数插值实现(第二边界条
- 太阳天顶角计算工具
- TDI驱动源代码
- KinectSDK2.0面部获取
- 种子填充算法VC程序.rar
- 实现了异常管理流程QtSharpCore.zip
- VC编写的简单聊天程序
- 利用USB虚拟总线驱动模拟USB摄像头的
评论
共有 条评论