導航:首頁 > 編程語言 > 手寫代碼

手寫代碼

發布時間: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
}
}
}

閱讀全文

與手寫代碼相關的資料

熱點內容
如何系統科學的自學編程知識 瀏覽:748
pr怎麼添加srt字幕文件 瀏覽:751
pc移動網站模板 瀏覽:142
我怎麼找回郵箱密碼 瀏覽:220
如何告訴編程人員編程的順序 瀏覽:965
3g4g網路怎麼設置 瀏覽:766
企業如何應對員工數據盜竊 瀏覽:991
怎麼下載借款大王app 瀏覽:760
探探的存儲文件夾 瀏覽: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

友情鏈接