导航:首页 > 编程语言 > 手写代码

手写代码

发布时间:2025-03-14 22:02:19

1. 网页手写页面代码具体是怎样写

手写代码的要求是说要求你对HTML、CSS、JS很熟悉,在离开IDE的情况下,用写字板等在没有IDE提示的情况下也能编写代码。

2. 台湾一公司在停电的时候让员工手写代码,你如何看待公司这一要求

台湾一公司在停电的时候让员工手写代码,公司的这个要求真的是有一些无理。手写代码有什么意义呢?来电之后不是还需要重新打在电脑上,那么这个手写就是在浪费时间,对于这样的公司不待也罢,而且感觉公司的老板根本都不懂什么叫做程序,什么叫做代码。

公司方面的回应也是很搞笑,没有办法,不能因为停电影响了工期,在停电之后,公司6名程序员都在工位上面用手机打光用执笔撰写代码,真的好想让这个老板来看一看,或者自己来写一写,写完之后他就知道这个代码到底有没有用了。这个消息也是小编今年以来听到的最搞笑的一个消息,希望大家都能够遇到一个有智商的老板。

3. JavaScript手写LRU算法的示例代码

LRU是Least Recently Used的缩写,即最近最少使用。作为一种经典的缓存策略,它通过将长期未使用的数据替换掉,来提高缓存的命中率。一、基本要求:固定大小,快速访问,以及在达到内存限制的情况下有效驱逐条目。二、数据结构


实现LRU有两种方式:一种是使用Map,另一种是使用双向链表。Map的特点是有序,当我们迭代时,可以按插入顺序返回键值。双向链表则通过增、删、改操作实现数据管理,同时通过Map存储对链表节点的引用以快速读取数据。


三、Map实现


在初始化时,需要配置存储限制和创建Map。在添加数据时,判断是否已存在相同数据并删除,再判断是否已满,若已满则删除头部数据。基于JavaScript Map实现LRU的代码如下:


class LRUCache {
size = 5
constructor(size) {
this.cache = new Map()
this.size = size || this.size
}
get(key) {
if (this.cache.has(key)) {
let temp = this.cache.get(key)
this.cache.delete(key)
this.cache.set(key, temp)
return temp
}
return null
}
set(key, value) {
if (this.cache.has(key)) {
this.cache.delete(key)
}
if (this.cache.size === this.size) {
this.cache.delete(this.cache.keys().next().value)
}
this.cache.set(key, value)
}


四、双向链表实现


1. 定义节点类,包含prev,next,data三个属性。
2. 定义链表类,包含head、tail属性,以及moveNodeToHead,insertNodeToHead,deleteLastNode方法。
3. 定义LRU类,包含linkLine,map和size属性,以及set和get方法。


五、代码实现


class LinkNode {
prev = null
next = null
constructor(key, value) {
this.data = { key, value }
}
}


class LinkLine {
head = null
tail = null
constructor() {
const headNode = new LinkNode('head', 'head')
const tailNode = new LinkNode('tail', 'tail')
headNode.next = tailNode
tailNode.prev = headNode
this.head = headNode
this.tail = tailNode
}
moveNodeToFirst(node) {
node.prev.next = node.next
node.next.prev = node.prev
this.insertNodeToFirst(node)
}
insertNodeToFirst(node) {
const second = this.head.next
this.head.next = node
node.prev = this.head
node.next = second
second.prev = node
}
delete(node) {
node.prev.next = node.next
node.next.prev = node.prev
}
deleteLastNode() {
const last = this.tail.prev
this.tail.prev = last.prev
last.prev.next = this.tail
return last
}
}


class LRUCache {
linkLine = null
map = {}
size = 5
constructor(size) {
this.size = size || this.size
this.linkLine = new LinkLine()
}
get(key) {
let value
if (this.map[key]) {
const node = this.map[key]
value = node.value
this.linkLine.moveNodeToFirst(node)
}
return value
}
set(key, value) {
if (this.map[key]) {
const node = this.map[key]
node.value = value
this.linkLine.moveNodeToFirst(node)
} else {
if (Object.keys(this.map).length === this.size) {
const lastNode = this.linkLine.deleteLastNode()
delete this.map[lastNode.data.key]
}
const newNode = new LinkNode(key, value)
this.linkLine.insertNodeToFirst(newNode)
this.map[key] = newNode
}
}
}

阅读全文

与手写代码相关的资料

热点内容
探探的存储文件夹 浏览:921
win10更新加载不出来 浏览:812
哪个app可以交罚款 浏览:87
java课程设计小型图书管理 浏览:624
手机qq收藏的文件目录 浏览:214
u盘7个g能装多少文件 浏览:403
浙江五轴编程培训哪里好 浏览:673
c盘的360文件删除不了怎么办 浏览:262
猫咪app安卓的哪里下载啊 浏览:379
loky什么网站 浏览:330
linux查看包含sys的文件 浏览:844
3dmax2012激活工具 浏览:615
flashcs5java 浏览:895
程序员软件设计师 浏览:339
哪个期货交易软件数据最快 浏览:269
电脑没有标志如何连接网络 浏览:886
文件夹里面的ps文件怎么显示预览 浏览:197
微信聊天文件怎么没有 浏览:290
win10玩红警心灵终结卡 浏览:443
发那科刚性攻丝怎么编程 浏览:774

友情链接