java - 如何在单车道桥问题上实现 FCFS 算法?
问题描述
如何在单车道桥问题上实现 FCFS 算法?
我正在研究单车道桥问题,并希望避免挨饿。
每当村民开始等待时,我想将他添加到等待队列的末尾,并且每当桥空闲时,我想将村民放在等待队列的顶部。
这是我的代码片段,无需担心饥饿且未实现 FIFO:
System.out.println("NorthBound Villager "+ count + " is waiting");
try
{
Thread.sleep(2);
}
catch (Exception e)
{
System.out.println(e);
}
bridge.crossBridge();
System.out.println("NorthBound Villager " + count + " is crossing the bridge");
try {
Thread.sleep(2);
} catch (Exception e) {
System.out.println(e);
}
System.out.println("NorthBound Villager " + count + "left the bridge");
bridge.left();
}
}
解决方案
推荐阅读
- mysql - Codeigniter 活动记录返回指定行的列名
- python - 数据框中的条形图
- java - 将Java中的对象列表序列化为json
- r - R Leaflet Shiny:shape_click$id 为 NULL
- jenkins - 如何在 Jenkinsfile 中捕获分支名称
- list - aVdin 8 中的样式列表选择
- codeigniter - 如何在codeigniter中添加外键迁移?
- gremlin - Gremlin 用例 - Int 属性和 coalesce()
- elasticsearch - 如何使 Elasticsearch 匹配包含句号作为单词分隔符的文档
- php - 大商取货不更新