• 数据结构


    function Node(element) { this.element = element; this.next = null; this.previous = null; }function LList() { this.head = new Node("head"); this.find = find; this.insert = insert; this.display = display; this.remove = remove; this.findLast = findLast; this.dispReverse = dispReverse; }function dispReverse() { var currNode = this.head; currNode = this.findLast(); while (!(currNode.previous == null)) { print(currNode.element); currNode = currNode.previous; } }function findLast() { var currNode = this.head; while (!(currNode.next == null)) { currNode = currNode.next; }return currNode; }function remove(item) { var currNode = this.find(item); if (!(currNode.next == null)) {currNode.previous.next = currNode.next; currNode.next.previous = currNode.previous; currNode.next = null; currNode.previous = null; } }function display() { var currNode = this.head; while (!(currNode.next == null)) { print(currNode.next.element); currNode = currNode.next; } }function find(item) { var currNode = this.head; while (currNode.element != item) { currNode = currNode.next; }return currNode; }function insert(newElement, item) { var newNode = new Node(newElement); var current = this.find(item); newNode.next = current.next; newNode.previous = current; current.next = newNode; }
    var cities = new LList(); cities.insert("Conway", "head"); cities.insert("Russellville", "Conway"); cities.insert("Carlisle", "Russellville"); cities.insert("Alma", "Carlisle"); cities.display(); console.log(); cities.remove("Carlisle"); cities.display();

     //双向链表

    字典模式

    function Dictionary() { this.add = add; this.datastore = new Array(); this.find = find; this.remove = remove; this.showAll = showAll; this.count = count; this.clear = clear; }function add(key, value) { this.datastore[key] = value; }function find(key) { return this.datastore[key]; }function remove(key) { delete this.datastore[key]; }function showAll() { for each (var key in Object.keys(this.datastore)) { print(key + " -> " + this.datastore[key]); } }function count() { var n = 0; for each (var key in Object.keys(this.datastore)) { ++n; }return n; }function clear() { for each (var key in Object.keys(this.datastore)) { delete this.datastore[key]; } }

    //字典模式中代码会报错,修改后执行

  • 相关阅读:
    【C/C++开发】c++ 工具库 (zz)
    【机器学习】半监督学习
    【Python开发】Pycharm下的Anaconda配置
    【C/C++开发】emplace_back() 和 push_back 的区别
    【C/C++开发】容器set和multiset,C++11对vector成员函数的扩展(cbegin()、cend()、crbegin()、crend()、emplace()、data())
    【C/C++开发】C++11 并发指南三(std::mutex 详解)
    【C/C++开发】C++11 并发指南二(std::thread 详解)
    【C/C++开发】C++11 并发指南一(C++11 多线程初探)
    【C/C++开发】STL内嵌数据类型: value_type
    个股实时监控之综述
  • 原文地址:https://www.cnblogs.com/jingguorui/p/13130594.html
Copyright © 2020-2023  润新知