当前位置: 首页 > news >正文

做静态头像网站上海装修网官网

做静态头像网站,上海装修网官网,wordpress 备份到云盘,王也天演过的电视剧请你设计并实现一个满足 LRU (最近最少使用) 缓存 约束的数据结构。 实现 LRUCache 类#xff1a; LRUCache(int capacity) 以 正整数 作为容量 capacity 初始化 LRU 缓存int get(int key) 如果关键字 key 存在于缓存中#xff0c;则返回关键字的值#xff0c;否则返回 -…请你设计并实现一个满足  LRU (最近最少使用) 缓存 约束的数据结构。 实现 LRUCache 类 LRUCache(int capacity) 以 正整数 作为容量 capacity 初始化 LRU 缓存int get(int key) 如果关键字 key 存在于缓存中则返回关键字的值否则返回 -1 。void put(int key, int value) 如果关键字 key 已经存在则变更其数据值 value 如果不存在则向缓存中插入该组 key-value 。如果插入操作导致关键字数量超过 capacity 则应该 逐出 最久未使用的关键字。 函数 get 和 put 必须以 O(1) 的平均时间复杂度运行。 思路一双向链表 c语言解法 struct LRUInfo{int val;int value;struct LRUInfo* pre;struct LRUInfo* next; };typedef struct {int top;int total;struct LRUInfo * head;struct LRUInfo * rear;struct LRUInfo lruinfo[10001]; } LRUCache;LRUCache* lRUCacheCreate(int capacity) {LRUCache* obj calloc(1, sizeof(LRUCache));obj-total capacity;obj-head calloc(1, sizeof(struct LRUInfo));obj-rear calloc(1, sizeof(struct LRUInfo));obj-head-next obj-rear;obj-rear-pre obj-head;return obj; }int lRUCacheGet(LRUCache* obj, int key) {if (obj-lruinfo[key].val 1) {obj-lruinfo[key].pre-next obj-lruinfo[key].next;obj-lruinfo[key].next-pre obj-lruinfo[key].pre;obj-rear-pre-next obj-lruinfo key;obj-lruinfo[key].pre obj-rear-pre;obj-lruinfo[key].next obj-rear;obj-rear-pre obj-lruinfo key;return obj-lruinfo[key].value;}return -1; }void lRUCachePut(LRUCache* obj, int key, int value) {if (obj-lruinfo[key].val 0 obj-top obj-total) {(obj-top);obj-rear-pre-next obj-lruinfo key;obj-lruinfo[key].pre obj-rear-pre;obj-lruinfo[key].next obj-rear;obj-lruinfo[key].val 1;obj-lruinfo[key].value value;obj-rear-pre obj-lruinfo key;} else if (obj-lruinfo[key].val 1){obj-lruinfo[key].pre-next obj-lruinfo[key].next;obj-lruinfo[key].next-pre obj-lruinfo[key].pre;obj-rear-pre-next obj-lruinfo key;obj-lruinfo[key].pre obj-rear-pre;obj-lruinfo[key].next obj-rear;obj-lruinfo[key].value value;obj-rear-pre obj-lruinfo key;} else if (obj-lruinfo[key].val 0 obj-top obj-total obj-head-next ! NULL) {obj-lruinfo[key].val 1;obj-lruinfo[key].value value;obj-rear-pre-next obj-lruinfo key;obj-lruinfo[key].pre obj-rear-pre;obj-lruinfo[key].next obj-rear;obj-rear-pre obj-lruinfo key;obj-head-next-val 0;obj-head-next obj-head-next-next;obj-head-next-pre obj-head; }return; }void lRUCacheFree(LRUCache* obj) {free(obj); }/*** Your LRUCache struct will be instantiated and called as such:* LRUCache* obj lRUCacheCreate(capacity);* int param_1 lRUCacheGet(obj, key);* lRUCachePut(obj, key, value);* lRUCacheFree(obj); */ 分析 本题要实现LRU缓存实现双向链表的各个操作后即可解决删除方法利用前驱节点的指针才能满足O(1)的时间复杂度get方法利用前驱节点达到O(1)的时间复杂度 总结 本题考察对LRU缓存的实现考虑到各个方法的实现的时间复杂度要求在O(1)所以采用双向链表保证时间复杂度最后实现各个方法即可解决
http://www.pierceye.com/news/49809/

相关文章:

  • 试玩网站开发建设产品网站课程
  • 易搜网站建设注册百度账号免费
  • 网站个人建设如何选择常州网站建设
  • 传奇新开网站微信小程序怎么制作游戏
  • 涿州建设局网站怎么做公司内网网站
  • 常州网站建设招聘凡科网登录下载
  • 网站开发中制作视频播放器什么网站是免费的
  • 门户网站推广优势win7优化大师好不好
  • 网站策划任职要求中国建筑装饰网网址
  • 网站开发外键常熟网站设计
  • 源码下载网站有哪些昆明网络推广
  • 网站建设项目付款方式网站备案查询中心
  • 鹤壁市建设局网站wordpress板块大小
  • 宁波建网站哪家值得信赖p站代理网址
  • 做地方的门户网站现在注册公司流程和费用
  • wordpress discuz郑州seo竞价
  • 厦门网站建设cnmxcm企业营销策略有哪些
  • 电商网站是什么建设银行 网站用户变成个人用户
  • 企业建设网站策划案公司网站介绍范文
  • 网站建设安全技术方面安全质量报监建设局网站
  • 龙华做棋牌网站建设哪家好网络营销网站建设公司
  • 网站更新提示怎末做学做美食看哪个网站
  • 如何在旅游网站上做攻略商丘三合一网站建设
  • 医疗网站优化怎么做wordpress签到积分主题
  • 襄阳市建设公司网站佛山网站建设 奇锐科技
  • seo网站快速排名郑州建站网站的公司
  • 在线旅游网站人力资源网站怎么做
  • 网站建设之婚礼摄影网站设计wordpress导航图标
  • jsp网站开发的mvc漂亮企业网站源码
  • 以家为主题做网站wordpress重装到恢复