m9rco / algorithm-php Goto Github PK
View Code? Open in Web Editor NEW🍭🍭uniting the internal work in a way that is in PHP
License: MIT License
🍭🍭uniting the internal work in a way that is in PHP
License: MIT License
一些查找算法的前提是 被查找的序列是顺序的 比如fibonacci查找, 测试的时候 那个数组不是顺序的
给定一个数据流,数据流长度N很大,且N直到处理完所有数据之前都不可知,请问如何在只遍历一遍数据(O(N))的情况下,能够随机选取出m个不重复的数据。
比如:
MBaseSort.php 基数排序 MSD
LBaseSort.php 基数排序 LSD
如果 未实现,最好标示一下。
vim .git/hooks/commit-msg
放入以下代码
#!/bin/bash
msg=$(head -n 1 $1)
if echo $msg | grep -iqE "^Merge "; then
exit 0
fi;
if echo $msg | grep -iqE "^Revert "; then
exit 0
fi;
gitmoji=(
:art:
:zap:
:fire:
:bug:
:ambulance:
:sparkles:
:memo:
:rocket:
:lipstick:
:tada:
:white_check_mark:
:lock:
:apple:
:penguin:
:checkered_flag:
:robot:
:green_apple:
:bookmark:
:rotating_light:
:construction:
:green_heart:
:arrow_down:
:arrow_up:
:construction_worker:
:chart_with_upwards_trend:
:hammer:
:heavy_minus_sign:
:whale:
:heavy_plus_sign:
:wrench:
:globe_with_meridians:
:pencil2:
:hankey:
:rewind:
:twisted_rightwards_arrows:
:package:
:alien:
:truck:
:page_facing_up:
:boom:
:bento:
:ok_hand:
:wheelchair:
:bulb:
:beers:
:speech_balloon:
:card_file_box:
:loud_sound:
:mute:
)
i=$(awk 'BEGIN{srand();fr=int(48*rand());print fr;}')
basepath=$(dirname `pwd`"/"$1"/COMMIT_EDITMSG" ;)
echo $msg ${gitmoji[$i]} > $basepath;
if echo $msg | grep -iqE "^(feat|fix|docs|style|refactor|perf|test|chore)(\([^()]{1,}\)){0,1}: .{1,}"; then
exit 0
fi;
echo
echo -e "\033[41mINVALID COMMIT MSG:\033[0m Does not match \"<type>(<scope>): <subject>\" !"
echo
cat <<EOF
Available types and what it mean are list here
feat: A new feature
fix: A bug fix
docs: Documentation only changes
style: Changes that do not affect the meaning of the code
(white-space, formatting, missing semi-colons, etc)
refactor: A code change that neither fixes a bug or adds a feature
perf: A code change that improves performance
test: Adding missing tests
chore: Changes to the build process or auxiliary tools
and libraries such as documentation generation
EOF
echo -e "Please read http://www.ruanyifeng.com/blog/2016/01/commit_message_change_log.html"
echo
exit 1
Unfortunately, I do not speak, nor can I read Chinese.
However, this project seems interesting and from what I managed to translate using google seems like a really interesting read.
Hopefully, someone who is fluent in both English and Chinese can translate this.
If we plan on translating to more than one language it would be worthwhile creating an 'English' branch and other languages could follow suit.
If we plan on translating only to English then an English translation under the Chinese comments would be ideal.
例如:以下URL中写的 冒泡排序及两种优化方式
供别人参考
Take me fly
建议示例跟代码剥离,写到专门的test里边去,然后建一个composer包来发布,这样别人使用和测试都比较方便
您好,新人最近在学习您的这个算法合集,发现一个问题,希望能和您探讨一下!如果说错了还望海涵!
关于BubbleSortV2函数, 我觉得代码应该是这样
function BubbleSortV2(array $container)
{
$count = count($container);
for ($i = 0; $i < **_$count - 1_**; $i++) {
for ($j = $i + 1; $j < $count; $j++) {
if ($container[$i] > $container[$j]) {
list($container[$i], $container[$j]) = array($container[$j], $container[$i]);
}
}
}
return $container;
}
原代码在比较的时候多进行了无意义的一轮。
假设$count = 4 ,即 $i = 3 的时候,还会进行一轮比较,这个时候 $j 都等于 4 了 里面的循环根本就不成立,还不如在之前就去掉,这样稍微严谨一点吧!
原代码如下
function BubbleSortV2(array $container)
{
$len = count($container);
// 也可以用foreach
for ($i = 0; $i < $len; $i++) {
for ($j = $i + 1; $j < $len; $j++) {
if ($container[$i] > $container[$j]) {
list($container[$i], $container[$j]) = array($container[$j], $container[$i]);
}
}
}
return $container;
}
print_r(BubbleSort([4, 21, 41, 2, 53, 1, 213, 31, 21, 423]));
如有错误,还望指正!!! 谢谢!!
学到了很多
在一本算法结构的书中,介绍的快速排序,每一趟排序都会去交换。
但这里的好像只是找到了比基准值大的和小的两个数组,然后最后再去合并。
书上的c的实现:
`int Quick(List R, int low, int high)
{
x=R[low];
while(low<high)
{
while((low<high) && R[high].key >= x.key)
{
high --;
}
R[low] = R[high];
while(low<high && R[low].key <= x.key)
{
low++;
}
R[high] = R[low];
}
R[low] = x;
return low;
}
void QuickSort(List R, int low, int high)
{
if (low < high)
{
temp = Quick(R, low, high);
QuickSort(R, low, temp - 1);
QuickSort(R, temp + 1, high);
}
}`
Hi there,
I couldn't find a SECURITY.md
in your repository and am not sure how to best contact you privately to disclose a security issue.
Can you add a SECURITY.md
file with an e-mail to your repository, so that our system can send you the vulnerability details? GitHub suggests that a security policy is the best way to make sure security issues are responsibly disclosed.
Once you've done that, you should receive an e-mail within the next hour with more info.
Thanks! (cc @huntr-helper)
REDAME
wiki
貌似用这个更合理。
$i = floor($this->count / 2);
您好,求问如何排序两个无序数组????
我现在的解题思路就是先将两个数组合并成一个,然后再归并,但是我感觉不太好
大佬这个算法有么?
例:
abcabcbb->abc
bbbbb->b
wpwwkew->wke
由于安全方面限制,要求我们不能保存用户的信用卡信息,包括信用卡过期时间.
但是可以通过一个 api, 单次调用获得 一个用户的 信用卡过期时间 .
现在要求 在用户信息用卡过期的前三天,给用户发送邮件通知 .
请问如何避免每天大量全库用户调用 API 来实现这个功能 .
(信用卡过期时间 为 年月 eg: 07/21 2021年07月过期 , 一般认为 当月的最后一天为过期时间)
php 里面 0== 'default' 是 true 导致了执行到$top=0的时候重新赋值$top=10 死循环了
改成下面的方式
if (!is_numeric($top) && $top == 'default')
{
$top = count($container);
}
@pushaowei 新合并的二叉树算法 没有在README 上体现
public function QulickSort(array $container){
$count = count($container);
if ($count <=1 ) {
return $container;
}
$left = $right = [];
for ( $i = 1; $i<$count; $i++ ){
if ( $container[$i] <= $container[0] ){
$left[] = $container[$i];
} else {
$right[]= $container[$i];
}
}
$left = $this->QulickSort($left);
$right = $this->QulickSort($right);
return array_merge($left,[$container[0]],$right);
}
/**
BubbleSort([4, 21, 41, 2, 53, 1, 213, 31, 21, 423]);
/*
第1步排序结果4,21,2,41,1,53,31,21,213,423
第2步排序结果4,2,21,1,41,31,21,53,213,423
第3步排序结果2,4,1,21,31,21,41,53,213,423
第4步排序结果2,1,4,21,21,31,41,53,213,423
第5步排序结果1,2,4,21,21,31,41,53,213,423
第6步排序结果1,2,4,21,21,31,41,53,213,423
第7步排序结果1,2,4,21,21,31,41,53,213,423
第8步排序结果1,2,4,21,21,31,41,53,213,423
第9步排序结果1,2,4,21,21,31,41,53,213,423
*/
function BubbleSortV2(array $container)
{
$len = count($container);
// 也可以用foreach
for ($i = 0; $i < $len; $i++) {
for ($j = $i + 1; $j < $len; $j++) {
if ($container[$i] > $container[$j]) {
list($container[$i], $container[$j]) = array($container[$j], $container[$i]);
}
}
}
return $container;
}
这样不是稳定排序了
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.