Python FIFO算法模拟
来源:互联网 发布:阿里云服务器免流教程 编辑:程序博客网 时间:2024/06/18 14:03
#!/usr/bin/python array = (7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 1, 2, 0, 1, 7, 0, 1)memory = []pointer = 0 # if the memory is empty def is_empty(_list_): if len(_list_) == 0: re1 = 1 else: re1 = 0 return re1 # if the memory is empty def is_fulled(_list_): if len(_list_) == 3: re1 = 1 else: re1 = 0 return re1 def search(target, _list_): exist = 0 for each_item in _list_: if each_item == target: exist = 1 break return exist # put in memory def push(target, _list_, temp): if is_empty(_list_) == 1 or is_fulled(_list_) == 0: _list_.append(target) else: if search(target, _list_) == 1: print('no exchange') else: if temp > 2: temp = 0 _list_.pop(temp) _list_.insert(temp, target) temp = temp + 1 else: _list_.pop(temp) _list_.insert(temp, target) temp = temp + 1 return temp for each_item in array: pointer = push(each_item, memory, pointer) print(memory)
结果:结果:
[7]
[7, 0]
[7, 0, 1]
[2, 0, 1]
no exchange
[2, 0, 1]
[2, 3, 1]
[2, 3, 0]
[4, 3, 0]
[4, 2, 0]
[4, 2, 3]
[0, 2, 3]
no exchange
[0, 2, 3]
no exchange
[0, 2, 3]
[0, 1, 3]
[0, 1, 2]
no exchange
[0, 1, 2]
no exchange
[0, 1, 2]
[7, 1, 2]
[7, 0, 2]
[7, 0, 1]
阅读全文
0 0
- Python FIFO算法模拟
- python FIFO算法模拟(又是重复造轮子)
- 模拟FIFO页面置换算法
- 模拟操作系统FIFO置换算法
- 模拟分页,FIFO,LRU,OPT算法
- 页面置换算法(FIFO,LRU,OPT)c模拟
- OPT, LRU, FIFO页面调度算法的模拟
- FIFO算法
- Python模拟RSA算法
- python模拟银行家算法
- python 模拟lru算法
- 软件模拟环形FIFO
- 虚存管理页面置换算法 — FIFO和RUL算法模拟实现
- 操作系统模拟页面调度算法(OPT、FIFO、LRU)演示(vc6.0调试通过)
- 操作系统模拟页面调度算法(OPT、FIFO、LRU)演示(vc2010调试通过)(二)
- OS 请求调页存储管理方式的FIFO、LRU、OPT、LFU置换算法模拟
- 模拟退火算法Python实现
- 模拟退火算法Python实现
- EasyUI实例--tree的使用3
- 后台JSON接收为毫秒数,在前台页面展示yyyy-MM-dd格式
- 推荐一下github上一键集合的微信和支付宝支付
- eclipse XML 全部提示开启
- 数据结构实验之查找三:树的种类统计
- Python FIFO算法模拟
- 今天闲来无事,写一波Java数组可好?
- 用navicate premium将.csv导入mysql时出现乱码
- 20171213Link
- 语言的骨髓是逻辑
- 23、Android开发基础之通过隐式意图来实现界面的跳转
- 视图,序列,同义词,表空间
- JQuery.Ajax()的data参数类型
- [JavaScript] 将秒转换为日期