Giter VIP home page Giter VIP logo

knowledge's Issues

数据结构》链表:循环链表会导致display方法死循环

因为insertAfter方法中,新插入的元素next指向下一元素,
将head的next指向自己,会导致最后一个元素的next永远指向head,
这个逻辑就是传说中的"衔尾蛇",
会使链表变为循环链表,从而使得不加终止判断的display方法陷入死循环
display方法修改如下,望修正

// 显示全部节点
    display: function () {
        var current = this.head
        // 加入终止判断,到最后一个元素(next指向head)结束,防止双向链表中发生死循环
        while (current.next&&current.next.data!='head') {
            console.log(current.next.data)
            current = current.next
        }
        console.log('======')
    }

数据结构》树:find方法没有做防御性编程,导致传入数值找不到时报错

修改后相关代码如下,在移动current到左右节点之前先判断左右节点是否存在,不存在就直接跳出:

        // 查找指定值
	find:function(data){
		var current=this.root;
		while(true){
			if(data==current.data){
				return current;
			}
			if(data<current.data){
				if(current.left){
					current=current.left;
				}else{
					break;
				}
			}
			if(data>current.data){
				if(current.right){
					current=current.right;
				}else{
					break;
				}
			}
		}
		return null;
	}

另外,英文拼写有误,先序(根)遍历是preOrder traversal,不是perOrder。
还有,除先序遍历,中序遍历,后序遍历以外,
还有按层遍历,按层遍历由于存在先入先出的特性,正好可以利用到之前队列的结构,望补充

拼写小错误

基础知识->函数->函数的内部属性
应该是arguments,而不是anguments

队列的性能问题

queue.md 中给出的队列实现中,出队操作在大多数 JS 引擎下是 O(n) 时间复杂度的。而正常的实现应该可以做到 O(1) 或至少均摊 O(1) 的复杂度。

建议把修改这一节的实现;或说明其中的实现仅为数据结构示例,不建议直接使用。

404

虽关注已久,可惜深入大佬 repo 恨晚。
大佬文章基本 404 了...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.