Giter Site home page Giter Site logo

liyiheng / blog-gen Goto Github PK

View Code? Open in Web Editor NEW
14.0 14.0 4.0 8.69 MB

乱七八糟的笔记和代码,浏览者将会产生眩晕、恶心等不适症状

Go 5.52% CSS 1.07% HTML 0.63% Shell 0.06% Rust 91.48% Python 0.14% Procfile 0.01% Vim Script 1.10%

blog-gen's People

Contributors

dependabot[bot] avatar liyiheng avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

blog-gen's Issues

nginx in docker

docker pull nginx
# -v /path/of/host:/path/of/container
docker run --name nginx \
     -v /etc/nginx:/etc/nginx:ro \
     -v /home/liyiheng/logs:/var/log/nginx \
     -p 80:80 -d nginx

整理一下排序算法吧

一小块一小块巧克力,每一块上面都写着数字,对他们进行排序,排好吃掉。
吃到一半时,醒了。擦擦口水看看手机,还早,继续睡。
忙了一天,想起早上的梦,整理一下常用的排序算法吧。
依稀记得梦中用的桶排序,就先拿它下手

桶排序

最简单的情况,假设有5个非负整数,分别是 3,4,7,1,0
其中最大为7,创建一个长度为8的数组tmpArr。
遍历这5个数,对与每一个数n,有 tmpArr[n]++
比如第一个数是3,则tmpArr[3]++

于是tmpArr最终结果为
[1,1,0,1,1,0,0,1,0,0]
这时候遍历tmpArr,依次输出tmpArr[i]个 i,便是排序结果:
0,1,3,4,7
类似的,含有负数的情况需要另一个tmpArrNegative来记录负数。
tmpArr每个元素称为一个桶,这个例子中每个桶最多只能放一个元素(或者说只能记录一个数字出现的次数)
如果要排序的数据类型是int64,如果其中最大值是1<<1000,一个int64占八个字节,
那么,上面的tmpArr就需要 (1<<1000 + 1)*8 这么大的空间,是8G零8个字节

一个桶放多个元素

还是只考虑非负情况,假设对以下几个数进行排序:
345, 8, 277, 22, 1, 54, 33, 27
其中,最大的数345是三位数。
第一次,只考虑最低位(比如345的最低位是5)

/*
----------------------------------------
|                               27
|       1   22  33  54  345     277 8
-------------------------------------------
|   0   1   2   3   4   5   6   7   8   9
-------------------------------------------
*/

第二次,考虑次低位(十位),比如1的十位是0

/*
-------------------------------------------
|   8   27
|   1   22      33  345 54      277  
-------------------------------------------
|   0   1   2   3   4   5   6   7   8   9
-------------------------------------------
*/

第三次,百位

/*
-------------------------------------------
|   54
|   33
|   27
|   22
|   8   
|   1       277 345        
-------------------------------------------
|   0   1   2   3   4   5   6   7   8   9
-------------------------------------------
*/

至此,完成了所有的位,
这时每个“桶”中的数也是有序的,只需要将所有桶中数据拼接到一起便是有序结果。
因此排序结果为:
1,8,22,27,33,54,277,345

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.