插入排序 直接插入排序的PHP实现 Straight Insertion Sort
来源:互联网 发布:java hashmap 红黑树 编辑:程序博客网 时间:2024/06/05 04:45
直接插入排序(straight insertion sort)的PHP实现,很有用的一个函数array_splice,用好了很强的函数。
01
function
out_arr(
$arr
) {
02
return
implode(
', '
,
$arr
).'
03
';
04
}
05
06
function
sort_straight_insertion(
$arr
) {
07
$ret
[] =
$arr
[0];
08
for
(
$i
= 1;
$i
<
count
(
$arr
);
$i
++ ) {
09
for
(
$j
= 0;
$j
<
count
(
$ret
);
$j
++ ) {
10
if
(
$arr
[
$i
] <
$ret
[
$j
] ) {
11
array_splice
(
$ret
,
$j
, 0,
array
(
$arr
[
$i
]));
12
break
;
13
}
14
}
15
if
(
count
(
$ret
) ==
$i
) {
16
$ret
[] =
$arr
[
$i
];
17
}
18
echo
sprintf(
'%3d'
,
$i
).
' : '
.out_arr(
$ret
);
19
}
20
}
21
22
echo
'<pre>'
;
23
$arr
= range(1, 20);
24
shuffle(
$arr
);
25
echo
'ORG : '
.out_arr(
$arr
);
26
sort_straight_insertion(
$arr
);
27
echo
'</pre>'
;
- 插入排序 直接插入排序的PHP实现 Straight Insertion Sort
- 直接插入排序(Straight Insertion Sort)
- 直接插入排序(Straight Insertion Sort)
- 直接插入排序(Straight Insertion Sort)
- 直接插入排序(Straight Insertion Sort)
- 直接插入排序(Straight Insertion Sort)
- 直接插入排序(Straight Insertion Sort)
- 直接插入排序算法(Straight Insertion Sort) Java实现
- PHP实现排序算法----直接插入排序(Straight Insertion Sort)
- PHP实现排序算法----直接插入排序(Straight Insertion Sort)
- 1.插入排序—直接插入排序(Straight Insertion Sort)
- 插入排序—直接插入排序(Straight Insertion Sort)
- 排序之直接插入排序(Straight Insertion Sort)
- 排序(三)之直接插入排序Straight Insertion Sort
- 八大排序算法_直接插入排序(Straight Insertion Sort)
- 直接插入排序(Insertion Sort)
- 直接插入排序(Insertion Sort)
- 直接插入排序(Insertion Sort)
- 我的CSDN
- wpf+.net 4.5 surface2.0 = 异步多点触控 时间轴 part4
- 我的VC++——对话框中显示GIF格式的图片
- 退出Python 环境
- c++ 中 sort 与 c 的去sort cmp 比较函数 书写区别,待总结
- 插入排序 直接插入排序的PHP实现 Straight Insertion Sort
- 自绘按钮的实现
- DevDiv移动开发社区编著的《Windows Phone开发实战体验(应用+游戏)》隆重登场啦
- arm linux 启动流程
- Android工程师怒斥360拦截弹窗广告
- wpf+.net 4.5 surface2.0 = 异步多点触控 时间轴 part5
- 设计模式之——模板方法
- 多线程的使用与注意事项
- 解决使用枚举串口类而造成无法无法解析的外部符号的问题