bl双性强迫侵犯h_国产在线观看人成激情视频_蜜芽188_被诱拐的少孩全彩啪啪漫画

如何用JavaScript實現功能齊全的單鏈表詳解-創新互聯

前言

成都創新互聯公司從2013年創立,是專業互聯網技術服務公司,擁有項目網站設計、網站制作網站策劃,項目實施與項目整合能力。我們以讓每一個夢想脫穎而出為使命,1280元城固做網站,已為上家服務,為城固各地企業和個人服務,聯系電話:18982081108

前端也要搞好數據結構哦!

用JavaScript實現了個單鏈表,通過LinkedList構造函數可實例化一個單鏈表數據結構的對象,所有的方法放到LinkedList構造函數的原型對象上,寫了暫時能想到的所有方法

GitHub源碼地址,下載可運行

實現

  • 通過LinkedList的類創建鏈表實例,鏈表下有添加,查找,刪除,顯示節點等方法
  • 鏈表初始默認有一個"_head"頭部節點,使用時隱藏
  • 按元素/索引 添加、刪除,未找到時返回錯誤,查找未找到時返回null或-1
  • let obj = new LinkedList()

方法介紹


查找

  • obj.find(item)通過item元素內容查找到該元素
  • obj.findIndex(index)通過index索引查找到該元素
  • obj.findIndexOf(item)通過item元素內容查找到該元素索引
  • obj.findPrev(item)通過item元素查找上一個節點元素

添加

  • obj.insert(item,newElement)在item元素后插入新元素
  • obj.push(item)在鏈表末尾插入item元素
  • obj.insertIndex(index,newElement)在index索引處插入新元素

刪除

  • obj.remove(item)刪除item元素
  • obj.removeIndex(index)刪除index索引處節點

其他

  • obj.size()返回該鏈表的長度
  • obj.display()數組形式返回該鏈表,便于觀察,測試
  • obj.reversal()鏈表順序反轉(遞歸)

方法代碼


鏈表類LinkedList

 function LinkedList (...rest) {
 this._head = new Node('_head') // 鏈表頭節點
 // 如果new時有傳進值,則添加到實例中
 if (rest.length) {
 this.insert(rest[0], '_head')
 for (let i = 1; i < rest.length; i++) {
 this.insert(rest[i], rest[i - 1])
 }
 }
 }
 LinkedList.prototype.find = find
 LinkedList.prototype.findPrev = findPrev
 LinkedList.prototype.findIndex = findIndex
 LinkedList.prototype.findIndexOf = findIndexOf
 LinkedList.prototype.push = push
 LinkedList.prototype.insert = insert
 LinkedList.prototype.insertIndex = insertIndex
 LinkedList.prototype.remove = remove
 LinkedList.prototype.removeIndex = removeIndex
 LinkedList.prototype.size = size
 LinkedList.prototype.display = display
 LinkedList.prototype.reversal = reversal

網站名稱:如何用JavaScript實現功能齊全的單鏈表詳解-創新互聯
本文網址:http://vcdvsql.cn/article6/hcoig.html

成都網站建設公司_創新互聯,為您提供網站設計面包屑導航、網站改版、微信公眾號小程序開發、商城網站

廣告

聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯

成都app開發公司