當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
【数据结构 JavaScript版】- web前端开发精品课程【红点工场】 --javascript-- 链表实现...
生活随笔
收集整理的這篇文章主要介紹了
【数据结构 JavaScript版】- web前端开发精品课程【红点工场】 --javascript-- 链表实现...
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
<!DOCTYPE html>
<html><head><title></title>
</head><body><script>//【數據結構 JavaScript版】- web前端開發精品課程【紅點工場】 --javascript-- 鏈表實現// 對象存儲的方式var linkSheet = function() {var head = null;var length = 0;var Node = function(element) {this.element = element;this.next = null;}// 鏈表尾部添加元素this.append = function(element) {var node = new Node(element)if (head == null) {head = node;} else {var current = head;while (current.next) {current = current.next;}}length++;}//鏈表插入元素this.insert = function(position, element) {if (position >= -1 && position < length) {var node = new Node(element);if (position == 0) {var current = head;head = node;head.next = current;} else {var index = 0;var current = head;var previous = null;while (index < position) {previous = current;current = current.next;index++;}previous.next = node;node.next = current;}length++;}}// 移除下標元素this.removeAt = function(position){if(position>-1&&position<length){if(position==0){var current = head;head = current.next;}else{var current = head;var previous = null;var index = 0;while(index<position){previous = current;current = current.next;index++;}previous.next= current.next;}length--;return current;}return null;}// 獲取元素下標this.indexOf = function(element){var current = head;var index = 0;while(current){if(current.element==element){return index;}current= current.next;index++;return index;}return -1;}// 移除元素this.remove = function(element){return this.removeAt(this.indexOf(element));}// 判斷為空this.isEmpty = function(){return length==0;}// 獲取長度this.size = function(){return length;}// 返回頭部this.getHead = function(){return head;}}</script>
</body></html>
轉載于:https://www.cnblogs.com/SunlikeLWL/p/10124318.html
超強干貨來襲 云風專訪:近40年碼齡,通宵達旦的技術人生總結
以上是生活随笔為你收集整理的【数据结构 JavaScript版】- web前端开发精品课程【红点工场】 --javascript-- 链表实现...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C#打印0到100的素数
- 下一篇: C#图解教程 第二十一章 命名空间和程序