liyiheng / blog-gen Goto Github PK
View Code? Open in Web Editor NEW乱七八糟的笔记和代码,浏览者将会产生眩晕、恶心等不适症状
乱七八糟的笔记和代码,浏览者将会产生眩晕、恶心等不适症状
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
希望持续制造恶心和不适
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.